-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
aws_lambda: Lambda version resource id changes on each synth without any changes #31427
Comments
I created a public repo to easily reproduce the issue |
Are you able to check if this.alias = new Alias(this, `Alias`, {
aliasName: "v0",
version: this.currentVersion as IVersion,
}); Check the document about currentVersion for more details as I am guessing it's relevant to how the hash is calculated.
Can you share the output of |
This is the output when I deploy it first and run
Obviously cloudformation fails during deployment as there was no change to the lambda code or configuration, because of this the creation of the new versio fails with the following error
|
Describe the bug
When running the
cdk synth
command, the resource id of the AWS::LAMBDA::VERSION always changes on each run.Regression Issue
Last Known Working CDK Version
No response
Expected Behavior
The version resource id should only change when the function actually changed or if we force a change.
Current Behavior
The resource id changes each and every time the
synth
command is executed both locally and on CI/CD pipelines.Reproduction Steps
The following stack reproduces the exact issue that I have in my project now.
What I already have discovered is that it only breaks when BOTH the
.addLayers
is called AND theProvider
class is initialized. If one of both is removed, the issue no longer happens. But we need theProvider
class as we want to add a custom resource in our cloudformation stack.Another important note is that it doesn't matter if the
ICLambda
construct is initialized inside the same stack or another stack underbin/stack.ts
. It also affects other stacks for some reason.Simply run
cdk synth
mutiple times and you'll see that there is a diff in the resourceId of the lambda version on each run.Possible Solution
No response
Additional Information/Context
As described in the repro steps. Important to know is that it happens when both
addLayers
is called on aFunction
construct ANDProvider
class is initialized somewhere. It doesn't matter if theFunction
instance is provided to theProvider
or not.I have been digging and it's always the
calculateFunctionHash
inpackages/aws-cdk-lib/aws-lambda/lib/function-hash.ts
that returns a different hash on each synth.CDK CLI Version
2.157.0 (build 7315a59)
Framework Version
2.157.0
Node.js Version
v20.13.1
OS
MacOS
Language
TypeScript
Language Version
5.1.6
Other information
No response
The text was updated successfully, but these errors were encountered: