Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

(aws-cloudfront): Unexpected diffs caused by cloudfront.Function

See original GitHub issue

Non 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 }'),
  1. synth and extract the function name
  2. 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.


  • CDK CLI Version : ALL
  • Framework Version: 1.109.0
  • Node.js Version: ALL
  • OS : ALL
  • Language (Version): ALL


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.


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:open
  • Created 2 years ago
  • Reactions:17
  • Comments:17 (15 by maintainers)

github_iconTop GitHub Comments

eladbcommented, Jul 18, 2021

@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).

SachinShekharcommented, Aug 10, 2022

Any update on this? Sometimes my deployment succeeds; sometimes it doesn’t.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found