-
Notifications
You must be signed in to change notification settings - Fork 4k
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] Function.prototype.currentVersion does not work with Code.fromCfnParameters #11433
Comments
The challenge here is that it's not possible for the CDK to know at synthesis time that your parameter values are changing. They are configured at the time of deployment. For this reason we recommend not using CloudFormation parameters. Instead, specify the s3 bucket and object names directly in your CDK app. |
Thanks for the reply, can you provide advise on how to adapt the official docs CI/CD pipeline example so that it doesn't use |
You are right. We do have conflicting recommendations in our docs. Unfortunately, I still don't have a good solution to automatically recompute a new lambda version when the cloudformation parameter values change. |
I don't think there is a way to fix this issue in the current design of the CDK. Since the value of the |
I'm dropping this here, as this issue is still open. This is relevant discussion from an internal ticket that may help external users. For @marcogrcr's issue, simply creating the version directly is likely the simplest way to achieve the desired behavior, but this still may help other users. Credit @rix0rrr for penning this. CloudFormation will not perform an update to ANY resource unless any of its Properties have a different value during the deployment. Failing that, you can also change the LogicalID of the resource, which is a bit more drastic (and requires you to have enough information at template generation time to do so---which we do not if the filename comes in via a CFN Parameter) Armed with that information: To make CloudFormation publish a new version, you will need to trigger a change to the properties of AWS::Lambda::Version as well, which are:
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-version.html The only way to do that in a sensible way is to make sure to pass the SHA256 of the code into the You will have to sequence a Custom Resource in between the I recommend Be sure to work a timestamp into either one of the properties of the AWS Custom Resource or its logical ID, to make sure it executes on every deployment (otherwise it will only execute once because of the rule I mentioned above). Alternatively, you might try to work the S3 path into the |
Next steps for this issue would be to take Niranjan's suggestion:
Then convert to a discussion so that this information is available to folks. But it's not something we will be able to address by changing the |
Function.prototype.currentVersion
does not work when the code of the Lambda function is created usingCode.fromCfnParameters()
. Given that the logical id of the version changes based onmd5
of the function configuration, a new version does not get created when the parameters of the stack change (since this happens at CloudFormation update time).Reproduction Steps
This will always print
MyFunctionCurrentVersion7FAFE164
because the function configuration is static:aws-cdk/packages/@aws-cdk/aws-lambda/lib/function-hash.ts
Lines 5 to 17 in eb6f3a9
What did you expect to happen?
Changing the parameters causes a new version to be created.
What actually happened?
Changing the parameters causes the lambda function to be updated, but a new version is not created.
Environment
1.73.0
1.73.0
12.13.0
10.14.6
4.0.3
Other
The deprecation of
Function.prototype.addVersion()
makes this confusing since it suggestsFunction.prototype.currentVersion
is the way to do Lambda versioning for all cases.aws-cdk/packages/@aws-cdk/aws-lambda/lib/function.ts
Lines 729 to 735 in eb6f3a9
However, it does not apply to all cases as shown in this bug. The non-deprecated workaround I found was to create an instance of
Version
directy:This change was introduced in #6771 in response to #6750 and #5334
This is 🐛 Bug Report
The text was updated successfully, but these errors were encountered: