Skip to content

Commit 2f1fc95

Browse files
authored
fix(cloudfront): EdgeFunction us-east-1 stack created in different account (#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*
1 parent 62195fe commit 2f1fc95

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

packages/@aws-cdk/aws-cloudfront/lib/experimental/edge-function.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,10 @@ export class EdgeFunction extends Resource implements lambda.IVersion {
218218
let edgeStack = stage.node.tryFindChild(edgeStackId) as Stack;
219219
if (!edgeStack) {
220220
edgeStack = new Stack(stage, edgeStackId, {
221-
env: { region: EdgeFunction.EDGE_REGION },
221+
env: {
222+
region: EdgeFunction.EDGE_REGION,
223+
account: Stack.of(this).account,
224+
},
222225
});
223226
}
224227
this.stack.addDependency(edgeStack);

packages/@aws-cdk/aws-cloudfront/test/experimental/edge-function.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,25 @@ describe('stacks', () => {
102102
});
103103
});
104104

105+
test('us-east-1 stack inherits account of parent stack', () => {
106+
new cloudfront.experimental.EdgeFunction(stack, 'MyFn', defaultEdgeFunctionProps());
107+
108+
const fnStack = getFnStack();
109+
110+
expect(fnStack.account).toEqual('111111111111');
111+
});
112+
113+
test('us-east-1 stack inherits account of parent stack, when parent stack account is undefined', () => {
114+
stack = new cdk.Stack(app, 'StackWithDefaultAccount', {
115+
env: { region: 'testregion' },
116+
});
117+
new cloudfront.experimental.EdgeFunction(stack, 'MyFn', defaultEdgeFunctionProps());
118+
119+
const fnStack = getFnStack();
120+
121+
expect(fnStack.account).toEqual(cdk.Aws.ACCOUNT_ID);
122+
});
123+
105124
test('creates minimal constructs if scope region is us-east-1', () => {
106125
app = new cdk.App();
107126
stack = new cdk.Stack(app, 'Stack', {

0 commit comments

Comments
 (0)