Skip to content

Commit 8f4d4d7

Browse files
authored
chore(stepfunction-tasks): eventbridge aws. event source prefix check is more strict than it should be (#30237)
1. fix the event source validation 2. move the validation from renderEntries() to validateEntries() 3. add unit tests ### Issue # (if applicable) Closes #30191 ### Reason for this change ### Description of changes ### Description of how you validated changes ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 516ecef commit 8f4d4d7

File tree

2 files changed

+34
-10
lines changed

2 files changed

+34
-10
lines changed

Diff for: packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/eventbridge/put-events.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -132,23 +132,23 @@ export class EventBridgePutEvents extends sfn.TaskStateBase {
132132
}
133133

134134
private renderEntries(): Object[] {
135+
// we should have validated all entries in validateEntries()
135136
return this.props.entries.map(entry => {
136-
if (entry.source?.startsWith('aws')) {
137-
throw new Error('Event source cannot start with "aws."');
138-
} else {
139-
return {
140-
Detail: entry.detail?.value,
141-
DetailType: entry.detailType,
142-
EventBusName: entry.eventBus?.eventBusArn,
143-
Source: entry.source,
144-
};
145-
}
137+
return {
138+
Detail: entry.detail?.value,
139+
DetailType: entry.detailType,
140+
EventBusName: entry.eventBus?.eventBusArn,
141+
Source: entry.source,
142+
};
146143
});
147144
}
148145

149146
private validateEntries(): void {
150147
if (this.props.entries.length <= 0) {
151148
throw new Error('Value for property `entries` must be a non-empty array.');
152149
}
150+
if (this.props.entries.some(e => e.source.startsWith('aws.'))) {
151+
throw new Error('Event source cannot start with "aws."');
152+
}
153153
}
154154
}

Diff for: packages/aws-cdk-lib/aws-stepfunctions-tasks/test/eventbridge/put-events.test.ts

+24
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,30 @@ describe('Put Events', () => {
161161
}).toThrowError('Unsupported service integration pattern');
162162
});
163163

164+
test('event source cannot start with "aws."', () => {
165+
expect(() => {
166+
new EventBridgePutEvents(stack, 'PutEvents', {
167+
entries: [{
168+
detail: sfn.TaskInput.fromText('MyDetail'),
169+
detailType: 'MyDetailType',
170+
source: 'aws.source',
171+
}],
172+
});
173+
}).toThrow(/Event source cannot start with "aws."/);
174+
});
175+
176+
test('event source can start with "aws" without trailing dot', () => {
177+
expect(() => {
178+
new EventBridgePutEvents(stack, 'PutEvents', {
179+
entries: [{
180+
detail: sfn.TaskInput.fromText('MyDetail'),
181+
detailType: 'MyDetailType',
182+
source: 'awssource',
183+
}],
184+
});
185+
}).not.toThrow(/Event source cannot start with "aws."/);
186+
});
187+
164188
test('provided EventBus', () => {
165189
// GIVEN
166190
const eventBus = new events.EventBus(stack, 'EventBus');

0 commit comments

Comments
 (0)