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

chore(stepfunction-tasks): eventbridge aws. event source prefix check is more strict than it should be #30237

Merged
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -132,23 +132,23 @@ 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,
};
});
}

private validateEntries(): void {
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."');
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down