Skip to content

Commit 8cc9f43

Browse files
Prohibit EB batch size to be greater than 10 (#439)
* task: Prohibit EB batch size to be greater than 10 * task: Reset env variable after test
1 parent 0686fa1 commit 8cc9f43

3 files changed

Lines changed: 41 additions & 2 deletions

File tree

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.1.20",
3+
"version": "1.1.21",
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
@@ -28,6 +28,10 @@ export const publishToEventBridge = ({ // eslint-disable-line import/prefer-defa
2828
step = 'publish',
2929
...opt
3030
} = {}) => {
31+
// EB Batchsize can not exceed 10 - since BATCH_SIZE is used in many places, we should reduce it to 10 here.
32+
if (batchSize > 10) {
33+
batchSize = 10;
34+
}
3135
if (endpointId) import('@aws-sdk/signature-v4-crt');
3236

3337
const connector = new Connector({

test/unit/sinks/eventbridge.test.js

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@ import 'mocha';
22
import { expect } from 'chai';
33
import sinon from 'sinon';
44
import _ from 'highland';
5-
5+
import { v4 } from 'uuid';
66
import { publishToEventBridge as publish } from '../../../src/sinks/eventbridge';
77

88
import Connector from '../../../src/connectors/eventbridge';
99

1010
describe('sinks/eventbridge.js', () => {
11+
const origBatchSize = process.env.BATCH_SIZE;
12+
afterEach(() => {
13+
// set back to state specified in package.json
14+
process.env.BATCH_SIZE = origBatchSize;
15+
});
1116
afterEach(sinon.restore);
1217

1318
it('should batch and publish', (done) => {
@@ -89,6 +94,36 @@ describe('sinks/eventbridge.js', () => {
8994
.done(done);
9095
});
9196

97+
it('should batch and publish, multiple', (done) => {
98+
process.env.BATCH_SIZE = 100;
99+
sinon.stub(Connector.prototype, 'putEvents').resolves({ FailedEntryCount: 0 });
100+
101+
const uows = [];
102+
for (let i = 1; i <= 15; i += 1) {
103+
const id = v4();
104+
uows.push({
105+
event: {
106+
id,
107+
type: `p${i}`,
108+
partitionKey: id,
109+
},
110+
});
111+
}
112+
113+
_(uows)
114+
.through(publish({ busName: 'b1', debug: (msg, v) => console.log(msg, v), metricsEnabled: true }))
115+
.collect()
116+
.tap((collected) => {
117+
// console.log(JSON.stringify(collected, null, 2));
118+
119+
expect(collected.length).to.equal(15);
120+
collected.forEach((c) => {
121+
expect(c.publishRequest.Entries.length < 11).to.be.true;
122+
});
123+
})
124+
.done(done);
125+
});
126+
92127
it('should not publish', (done) => {
93128
const uows = [{
94129
}];

0 commit comments

Comments
 (0)