diff --git a/packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/eventbridge/put-events.ts b/packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/eventbridge/put-events.ts index cb0f08bb9a311..dfb8694d801c6 100644 --- a/packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/eventbridge/put-events.ts +++ b/packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/eventbridge/put-events.ts @@ -132,17 +132,14 @@ export class EventBridgePutEvents extends sfn.TaskStateBase { } private renderEntries(): Object[] { + // we should have validated all entries in validateEntries() return this.props.entries.map(entry => { - if (entry.source?.startsWith('aws')) { - throw new Error('Event source cannot start with "aws."'); - } else { - return { - Detail: entry.detail?.value, - DetailType: entry.detailType, - EventBusName: entry.eventBus?.eventBusArn, - Source: entry.source, - }; - } + return { + Detail: entry.detail?.value, + DetailType: entry.detailType, + EventBusName: entry.eventBus?.eventBusArn, + Source: entry.source, + }; }); } @@ -150,5 +147,8 @@ export class EventBridgePutEvents extends sfn.TaskStateBase { if (this.props.entries.length <= 0) { throw new Error('Value for property `entries` must be a non-empty array.'); } + if (this.props.entries.some(e => e.source.startsWith('aws.'))) { + throw new Error('Event source cannot start with "aws."'); + } } } \ No newline at end of file diff --git a/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/eventbridge/put-events.test.ts b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/eventbridge/put-events.test.ts index 67e98c798d32e..5a4a63221b504 100644 --- a/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/eventbridge/put-events.test.ts +++ b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/eventbridge/put-events.test.ts @@ -161,6 +161,30 @@ describe('Put Events', () => { }).toThrowError('Unsupported service integration pattern'); }); + test('event source cannot start with "aws."', () => { + expect(() => { + new EventBridgePutEvents(stack, 'PutEvents', { + entries: [{ + detail: sfn.TaskInput.fromText('MyDetail'), + detailType: 'MyDetailType', + source: 'aws.source', + }], + }); + }).toThrow(/Event source cannot start with "aws."/); + }); + + test('event source can start with "aws" without trailing dot', () => { + expect(() => { + new EventBridgePutEvents(stack, 'PutEvents', { + entries: [{ + detail: sfn.TaskInput.fromText('MyDetail'), + detailType: 'MyDetailType', + source: 'awssource', + }], + }); + }).not.toThrow(/Event source cannot start with "aws."/); + }); + test('provided EventBus', () => { // GIVEN const eventBus = new events.EventBus(stack, 'EventBus');