Skip to content

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

Merged
merged 3 commits into from
Jan 13, 2023

Conversation

rix0rrr
Copy link
Contributor

@rix0rrr rix0rrr commented Jan 10, 2023

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:

fn.invalidateVersionBasedOn(...);

Function to help invalidate the version using outside information.


All Submissions:

Adding new Construct Runtime Dependencies:

  • This PR adds new construct runtime dependencies following the process described here

New Features

  • Have you added the new feature to an integration test?
    • Did you use 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

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.
@rix0rrr rix0rrr requested a review from a team January 10, 2023 15:46
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Jan 10, 2023
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a 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.

@rix0rrr rix0rrr added the pr-linter/exempt-integ-test The PR linter will not require integ test changes label Jan 10, 2023
@aws-cdk-automation aws-cdk-automation dismissed their stale review January 10, 2023 18:41

✅ Updated pull request passes all PRLinter validations. Dissmissing previous PRLinter review.

@gitpod-io
Copy link

gitpod-io bot commented Jan 11, 2023

@Naumel Naumel added the pr/do-not-merge This PR should not be merged at this time. label Jan 12, 2023
Copy link
Contributor

@Naumel Naumel left a 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 = '') {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@rix0rrr rix0rrr removed the pr/do-not-merge This PR should not be merged at this time. label Jan 13, 2023
@rix0rrr
Copy link
Contributor Author

rix0rrr commented Jan 13, 2023

Is this change linked to any issue (I might have missed the link)?

Yes but I cannot link to it 🤓

@rix0rrr rix0rrr changed the title fix(lambda): inconsistent Version hash when LayerVersions from tokens fix(lambda): ever-changing Version hash when LayerVersions from tokens Jan 13, 2023
@rix0rrr rix0rrr changed the title fix(lambda): ever-changing Version hash when LayerVersions from tokens fix(lambda): ever-changing Version hash with LayerVersions from tokens Jan 13, 2023
@rix0rrr rix0rrr changed the title fix(lambda): ever-changing Version hash with LayerVersions from tokens fix(lambda): ever-changing Version hash with LayerVersion from tokens Jan 13, 2023
@github-actions github-actions bot added the p2 label Jan 13, 2023
@mergify
Copy link
Contributor

mergify bot commented Jan 13, 2023

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-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 79cc3ad
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit 88fc62d into main Jan 13, 2023
@mergify mergify bot deleted the huijbers/layer-version branch January 13, 2023 09:27
@mergify
Copy link
Contributor

mergify bot commented Jan 13, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution/core This is a PR that came from AWS. p2 pr-linter/exempt-integ-test The PR linter will not require integ test changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants