-
Notifications
You must be signed in to change notification settings - Fork 4.1k
fix(lambda): ever-changing Version hash with LayerVersion from tokens #23629
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
Conversation
If `LayerVersions` are referenced using tokens (`LayerVersion.fromLayerVersionArn(this, 'Layer', /* some deploy-time value */`) then the version hash would incorrectly use the string representation of the tokenized ARN and be different on every deployment, incorrectly trying to create a new `Version` object on every deployment. Resolve the ARN if we detect this. However, this will not be complete: we now have the problem that a new Version will not be created if it were necessary, since CDK cannot read the deploy-time value of the ARN and cannot mix it into the Version LogicalID if necessary. To fix that, add a: ```ts fn.invalidateVersionBasedOn(...); ``` Function to help invalidate the version using outside information.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.
✅ Updated pull request passes all PRLinter validations. Dissmissing previous PRLinter review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this change linked to any issue (I might have missed the link)?
import { md5hash } from '@aws-cdk/core/lib/helpers-internal'; | ||
import { LAMBDA_RECOGNIZE_LAYER_VERSION, LAMBDA_RECOGNIZE_VERSION_PROPS } from '@aws-cdk/cx-api'; | ||
import { Function as LambdaFunction } from './function'; | ||
import { ILayerVersion } from './layers'; | ||
|
||
export function calculateFunctionHash(fn: LambdaFunction) { | ||
export function calculateFunctionHash(fn: LambdaFunction, additional: string = '') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit] is the additional
more like salt
or would that name be too obtruse for the intent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is actually salt
. I suppose I could have included that word here, but in the public API I purposely didn't want to use the word salt
because that's extremely computer-sciency and I was trying to sound approachable.
Yes but I cannot link to it 🤓 |
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
If
LayerVersions
are referenced using tokens(
LayerVersion.fromLayerVersionArn(this, 'Layer', /* some deploy-time value */
) then the version hash would incorrectly use the string representation of the tokenized ARN and be different on every deployment, incorrectly trying to create a newVersion
object on every deployment.Resolve the ARN if we detect this.
However, this will not be complete: we now have the problem that a new Version will not be created if it were necessary, since CDK cannot read the deploy-time value of the ARN and cannot mix it into the Version LogicalID if necessary.
To fix that, add a:
Function to help invalidate the version using outside information.
All Submissions:
Adding new Construct Runtime Dependencies:
New Features
yarn integ
to deploy the infrastructure and generate the snapshot (i.e.yarn integ
without--dry-run
)?By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license