Skip to content

Commit

Permalink
fix(cloudfront): EdgeFunction us-east-1 stack created in different ac…
Browse files Browse the repository at this point in the history
…count (#13055)

The us-east-1 stack for EdgeFunction was defaulting to the default deploy
account. This means that using one account to deploy, and another for the stack
which contains the EdgeFunction, the support stack in us-east-1 will be deployed
into the deploy account, rather than stack account.

This fix has the us-east-1 stack inherit the account from the parent stack.

fixes #12789


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
njlynch authored Feb 15, 2021
1 parent 62195fe commit 2f1fc95
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,10 @@ export class EdgeFunction extends Resource implements lambda.IVersion {
let edgeStack = stage.node.tryFindChild(edgeStackId) as Stack;
if (!edgeStack) {
edgeStack = new Stack(stage, edgeStackId, {
env: { region: EdgeFunction.EDGE_REGION },
env: {
region: EdgeFunction.EDGE_REGION,
account: Stack.of(this).account,
},
});
}
this.stack.addDependency(edgeStack);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,25 @@ describe('stacks', () => {
});
});

test('us-east-1 stack inherits account of parent stack', () => {
new cloudfront.experimental.EdgeFunction(stack, 'MyFn', defaultEdgeFunctionProps());

const fnStack = getFnStack();

expect(fnStack.account).toEqual('111111111111');
});

test('us-east-1 stack inherits account of parent stack, when parent stack account is undefined', () => {
stack = new cdk.Stack(app, 'StackWithDefaultAccount', {
env: { region: 'testregion' },
});
new cloudfront.experimental.EdgeFunction(stack, 'MyFn', defaultEdgeFunctionProps());

const fnStack = getFnStack();

expect(fnStack.account).toEqual(cdk.Aws.ACCOUNT_ID);
});

test('creates minimal constructs if scope region is us-east-1', () => {
app = new cdk.App();
stack = new cdk.Stack(app, 'Stack', {
Expand Down

0 comments on commit 2f1fc95

Please sign in to comment.