(aws-cloudfront): Unexpected diffs caused by cloudfront.Function
See original GitHub issueNon deterministic auto-generated function name causing unexpected diffs.
Reproduction Steps
Using this code:
new cloudfront.Function(stack, 'Function', {
code: cloudfront.FunctionCode.fromInline('function handler(event) { return event.request }'),
});
- synth and extract the function name
- synth again and extract the function name
The function name is different for every synth.
What did you expect to happen?
The function name should be the same.
What actually happened?
Function name changes per synth.
Environment
- CDK CLI Version : ALL
- Framework Version: 1.109.0
- Node.js Version: ALL
- OS : ALL
- Language (Version): ALL
Other
This happens because of:
Where Stack.of(this).region
is an unresolved token that can have a different sequence number every time the program is executed.
A workaround right now would be to provide a name explicitly and not rely on this logic.
Workaround
Provide an explicit name for cloudfront.Function
. Using this.node.addr
or Node.of(this).addr
will return a stable fixed length unique id. Example:
const functionId = `MyFunction${this.node.addr}`;
new cloudfront.Function(stack, functionId, {
code: cloudfront.FunctionCode.fromInline('function handler(event) { return event.request }'),
functionName: functionId
});
This is 🐛 Bug Report
Issue Analytics
- State:
- Created 2 years ago
- Reactions:17
- Comments:17 (15 by maintainers)
Top Results From Across the Web
Troubleshoot issues where traffic is routed to an unexpected ...
I'm using Amazon CloudFront to distribute my web content. However, the traffic to my website is routed to the wrong edge location.
Read more >Customizing at the edge with functions - Amazon CloudFront
With Amazon CloudFront, you can write your own code to customize how your CloudFront distributions process HTTP requests and responses.
Read more >Restrictions on edge functions - Amazon CloudFront
The following topics describe the restrictions that apply to CloudFront Functions and Lambda@Edge. Some restrictions apply to all edge functions, ...
Read more >How do I resolve the error "CloudFront wasn't able to connect ...
There's a host header mismatch in the SSL negotiation between your CloudFront distribution and the custom origin. The custom origin isn't ...
Read more >Troubleshoot the CloudFront distribution “X-Cache:Miss from ...
If you're seeing the "X-Cache:Miss from CloudFront" response intermittently, then CloudFront might be removing the object because of infrequent ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@madeline-k I don’t believe I would tag it as p2 as basically the entire
cloudfront.Function
feature is broken in this situation. I would tag it as a p1.Also, please add the workaround to the issue description so people don’t have to search for it.
Here is what we did in construct-hub (source).
Any update on this? Sometimes my deployment succeeds; sometimes it doesn’t.