Skip to content

Commit

Permalink
fix(events): cannot use the same target account for 2 cross-account e…
Browse files Browse the repository at this point in the history
…vent sources

We hard code the SID of the EventBusPolicy that we generate in the account
of the target of a cross-account CloudWatch Event rule.
Which means that, if you have two sources in different accounts generating
events into the same target account,
you will get an error on CloudFormation deployment time about a duplicate SID.
Include the source account ID when generating the SID to make it unique.

Fixes aws#8010
  • Loading branch information
skinny85 committed May 19, 2020
1 parent 613df1b commit 4044dd4
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-events/lib/rule.ts
Expand Up @@ -244,7 +244,7 @@ export class Rule extends Resource implements IRule {
});
new CfnEventBusPolicy(eventBusPolicyStack, 'GivePermToOtherAccount', {
action: 'events:PutEvents',
statementId: 'MySid',
statementId: `Allow-account-${sourceAccount}`,
principal: sourceAccount,
});
}
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-events/test/test.rule.ts
Expand Up @@ -717,7 +717,7 @@ export = {
const eventBusPolicyStack = app.node.findChild(`EventBusPolicy-${sourceAccount}-us-west-2-${targetAccount}`) as cdk.Stack;
expect(eventBusPolicyStack).to(haveResourceLike('AWS::Events::EventBusPolicy', {
'Action': 'events:PutEvents',
'StatementId': 'MySid',
'StatementId': `Allow-account-${sourceAccount}`,
'Principal': sourceAccount,
}));

Expand Down

0 comments on commit 4044dd4

Please sign in to comment.