Skip to content

Commit 8772eef

Browse files
authored
add-eb-global-support (#400)
* add-eb-global-support * v1.0.33
1 parent f097c22 commit 8772eef

4 files changed

Lines changed: 51 additions & 3 deletions

File tree

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "aws-lambda-stream",
3-
"version": "1.0.32",
3+
"version": "1.0.33",
44
"description": "Create stream processors with AWS Lambda functions.",
55
"keywords": [
66
"aws",

src/sinks/eventbridge.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export const publishToEventBridge = ({ // eslint-disable-line import/prefer-defa
2121
maxPublishRequestSize = Number(process.env.PUBLISH_MAX_REQ_SIZE) || Number(process.env.MAX_REQ_SIZE) || 256 * 1024,
2222
batchSize = Number(process.env.PUBLISH_BATCH_SIZE) || Number(process.env.BATCH_SIZE) || 10,
2323
parallel = Number(process.env.PUBLISH_PARALLEL) || Number(process.env.PARALLEL) || 8,
24+
endpointId = process.env.BUS_ENDPOINT_ID,
2425
handleErrors = true,
2526
retryConfig,
2627
step = 'publish',
@@ -47,6 +48,9 @@ export const publishToEventBridge = ({ // eslint-disable-line import/prefer-defa
4748
Entries: batchUow.batch
4849
.filter((uow) => uow[publishRequestEntryField])
4950
.map((uow) => uow[publishRequestEntryField]),
51+
...(endpointId && {
52+
EndpointId: endpointId,
53+
}),
5054
},
5155
});
5256

test/unit/sinks/eventbridge.test.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,4 +270,48 @@ describe('sinks/eventbridge.js', () => {
270270
})
271271
.done(done);
272272
});
273+
274+
it('should publish to global endpoint', (done) => {
275+
sinon.stub(Connector.prototype, 'putEvents').resolves({ FailedEntryCount: 0 });
276+
277+
const uows = [{
278+
event: {
279+
id: '79a0d8f0-0eef-11ea-8d71-362b9e155667',
280+
type: 'p1',
281+
partitionKey: '79a0d8f0-0eef-11ea-8d71-362b9e155667',
282+
},
283+
}];
284+
285+
_(uows)
286+
.through(publish({ busName: 'b1', debug: (msg, v) => console.log(msg, v), endpointId: 'ep1' }))
287+
.collect()
288+
.tap((collected) => {
289+
// console.log(JSON.stringify(collected, null, 2));
290+
291+
expect(collected.length).to.equal(1);
292+
expect(collected[0].publishRequest).to.deep.equal({
293+
EndpointId: 'ep1',
294+
Entries: [{
295+
EventBusName: 'b1',
296+
Source: 'custom',
297+
DetailType: 'p1',
298+
Detail: JSON.stringify({
299+
id: '79a0d8f0-0eef-11ea-8d71-362b9e155667',
300+
type: 'p1',
301+
partitionKey: '79a0d8f0-0eef-11ea-8d71-362b9e155667',
302+
tags: {
303+
account: 'undefined',
304+
region: 'us-west-2',
305+
stage: 'undefined',
306+
source: 'undefined',
307+
functionname: 'undefined',
308+
pipeline: 'undefined',
309+
skip: true,
310+
},
311+
}),
312+
}],
313+
});
314+
})
315+
.done(done);
316+
});
273317
});

0 commit comments

Comments
 (0)