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

fix(cloudfront): cross-region EdgeFunction does not work within a Stage #12103

Merged
merged 2 commits into from
Jan 5, 2021
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 @@ -201,8 +201,8 @@ export class EdgeFunction extends Resource implements lambda.IVersion {
}

private edgeStack(stackId?: string): Stack {
const stage = this.node.root;
if (!stage || !Stage.isStage(stage)) {
const stage = Stage.of(this);
if (!stage) {
throw new Error('stacks which use EdgeFunctions must be part of a CDK app or stage');
}
const region = this.env.region;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,32 @@ describe('stacks', () => {
const fn2Stack = app.node.findChild(fn2StackId) as cdk.Stack;
expect(fn2Stack).toCountResources('AWS::Lambda::Function', 1);
});

test('cross-region stack supports defining functions within stages', () => {
app = new cdk.App();
const stage = new cdk.Stage(app, 'Stage');
stack = new cdk.Stack(stage, 'Stack', {
env: { account: '111111111111', region: 'testregion' },
});

new cloudfront.experimental.EdgeFunction(stack, 'MyFn', defaultEdgeFunctionProps());

// Because 'expect(stack)' doesn't work correctly for stacks in nested assemblies
const stackArtifact = stage.synth().getStackArtifact(stack.artifactId);
expect(stackArtifact).toHaveResourceLike('AWS::Lambda::Function', {
Handler: '__entrypoint__.handler',
Role: {
'Fn::GetAtt': ['CustomCrossRegionStringParameterReaderCustomResourceProviderRole71CD6825', 'Arn'],
},
});
expect(stackArtifact).toHaveResource('Custom::CrossRegionStringParameterReader', {
ServiceToken: {
'Fn::GetAtt': ['CustomCrossRegionStringParameterReaderCustomResourceProviderHandler65B5F33A', 'Arn'],
},
Region: 'us-east-1',
ParameterName: 'EdgeFunctionArnMyFn',
});
});
});

test('addAlias() creates alias in function stack', () => {
Expand Down