Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add-eb-global-support #400

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aws-lambda-stream",
"version": "1.0.30",
"version": "1.0.31",
"description": "Create stream processors with AWS Lambda functions.",
"keywords": [
"aws",
Expand Down
4 changes: 4 additions & 0 deletions src/sinks/eventbridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const publishToEventBridge = ({ // eslint-disable-line import/prefer-defa
maxPublishRequestSize = Number(process.env.PUBLISH_MAX_REQ_SIZE) || Number(process.env.MAX_REQ_SIZE) || 256 * 1024,
batchSize = Number(process.env.PUBLISH_BATCH_SIZE) || Number(process.env.BATCH_SIZE) || 10,
parallel = Number(process.env.PUBLISH_PARALLEL) || Number(process.env.PARALLEL) || 8,
endpointId = process.env.BUS_ENDPOINT_ID,
handleErrors = true,
retryConfig,
step = 'publish',
Expand All @@ -47,6 +48,9 @@ export const publishToEventBridge = ({ // eslint-disable-line import/prefer-defa
Entries: batchUow.batch
.filter((uow) => uow[publishRequestEntryField])
.map((uow) => uow[publishRequestEntryField]),
...(endpointId && {
EndpointId: endpointId,
}),
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • jumping thru a hoop here with this condition to keep unit tests backwards compatible
  • otherwise it will be necessary to assert EndpointId: undefined in many tests

},
});

Expand Down
44 changes: 44 additions & 0 deletions test/unit/sinks/eventbridge.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,4 +249,48 @@ describe('sinks/eventbridge.js', () => {
})
.done(done);
});

it('should publish to global endpoint', (done) => {
sinon.stub(Connector.prototype, 'putEvents').resolves({ FailedEntryCount: 0 });

const uows = [{
event: {
id: '79a0d8f0-0eef-11ea-8d71-362b9e155667',
type: 'p1',
partitionKey: '79a0d8f0-0eef-11ea-8d71-362b9e155667',
},
}];

_(uows)
.through(publish({ busName: 'b1', debug: (msg, v) => console.log(msg, v), endpointId: 'ep1' }))
.collect()
.tap((collected) => {
// console.log(JSON.stringify(collected, null, 2));

expect(collected.length).to.equal(1);
expect(collected[0].publishRequest).to.deep.equal({
EndpointId: 'ep1',
Entries: [{
EventBusName: 'b1',
Source: 'custom',
DetailType: 'p1',
Detail: JSON.stringify({
id: '79a0d8f0-0eef-11ea-8d71-362b9e155667',
type: 'p1',
partitionKey: '79a0d8f0-0eef-11ea-8d71-362b9e155667',
tags: {
account: 'undefined',
region: 'us-west-2',
stage: 'undefined',
source: 'undefined',
functionname: 'undefined',
pipeline: 'undefined',
skip: true,
},
}),
}],
});
})
.done(done);
});
});