Skip to content
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): Layer updates not creating new function version #19098

Closed
varju opened this issue Feb 23, 2022 · 2 comments · Fixed by #20150
Closed

(aws-lambda): Layer updates not creating new function version #19098

varju opened this issue Feb 23, 2022 · 2 comments · Fixed by #20150
Assignees
Labels
@aws-cdk/aws-lambda Related to AWS Lambda bug This issue is a bug. effort/medium Medium work item – several days of effort p1

Comments

@varju
Copy link
Contributor

varju commented Feb 23, 2022

What is the problem?

If my stack contains a Lambda LayerVersion and a Lambda Function with an alias pointing to the newest version, content changes within the layer do not trigger deployment of a new Function version.

Reproduction Steps

Example stack demonstrating the problem:

export class CdkLayerExampleStack extends cdk.Stack {
  constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    const layer = new lambda.LayerVersion(this, 'MyLayer', {
      code: lambda.Code.fromAsset('layer-code'),
      compatibleRuntimes: [lambda.Runtime.NODEJS_14_X],
      description: 'A layer to test the L2 construct',
    });

    const fn = new lambda.Function(this, 'MyLayeredLambda', {
      code: lambda.Code.fromAsset('function-code'),
      handler: 'index.handler',
      runtime: lambda.Runtime.NODEJS_14_X,
      layers: [layer],
    });

    fn.currentVersion.addAlias('live');
  }
}

The layer contents, defined in layer-code/nodejs/node_modules/layer.js:

exports.getLayerVersion = function() {
  return 'V1';
}

The Lambda function, defined in function-code/index.js:

const layer = require('layer');

exports.handler = async function(event, context) {
  const functionVersion = 'V1';
  const layerVersion = layer.getLayerVersion();

  return {
    functionVersion,
    layerVersion,
  }
};

In cdk.json:

{
  "app": "npx ts-node --prefer-ts-exts bin/cdk-layer-example.ts",
  "context": {
    "@aws-cdk/core:newStyleStackSynthesis": "true",
    "@aws-cdk/aws-apigateway:usagePlanKeyOrderInsensitiveId": true,
    "@aws-cdk/core:enableStackNameDuplicates": "true",
    "aws-cdk:enableDiffNoFail": "true",
    "@aws-cdk/core:stackRelativeExports": "true",
    "@aws-cdk/aws-ecr-assets:dockerIgnoreSupport": true,
    "@aws-cdk/aws-secretsmanager:parseOwnedSecretName": true,
    "@aws-cdk/aws-kms:defaultKeyPolicies": true,
    "@aws-cdk/aws-s3:grantWriteWithoutAcl": true,
    "@aws-cdk/aws-ecs-patterns:removeDefaultDesiredCount": true,
    "@aws-cdk/aws-rds:lowercaseDbIdentifier": true,
    "@aws-cdk/aws-efs:defaultEncryptionAtRest": true,
    "@aws-cdk/aws-lambda:recognizeVersionProps": true,
    "@aws-cdk/aws-cloudfront:defaultSecurityPolicyTLSv1.2_2021": true
  }
}

What did you expect to happen?

Making content changes within layer-code/nodejs/node_modules/layer.js should trigger deployment of a new layer version and new function version, updating the live alias to point to the new function version.

What actually happened?

A new layer version was created, as expected, but a new function version was not created. Invoking the function directly shows that the new layer version is being used, but invoking the function alias shows the old layer version is still in use.

CDK CLI Version

1.143.0 (build bebd295)

Framework Version

No response

Node.js Version

v16.13.2

OS

macOS 12.2

Language

Typescript

Language Version

No response

Other information

No response

@varju varju added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Feb 23, 2022
@github-actions github-actions bot added the @aws-cdk/aws-lambda Related to AWS Lambda label Feb 23, 2022
@ryparker ryparker added p2 p1 and removed p2 labels Feb 23, 2022
@kaizencc kaizencc added effort/small Small work item – less than a day of effort and removed needs-triage This issue or PR still needs to be triaged. labels Mar 10, 2022
@kaizencc kaizencc removed their assignment Mar 11, 2022
@kaizencc kaizencc self-assigned this Apr 29, 2022
@kaizencc kaizencc added effort/medium Medium work item – several days of effort and removed effort/small Small work item – less than a day of effort labels May 26, 2022
@mergify mergify bot closed this as completed in #20150 May 31, 2022
mergify bot pushed a commit that referenced this issue May 31, 2022
Fixes #19098.

This introduces two bug fixes that are hidden behind a feature flag to preserve the current hash:

- lambda layer order is ignored by the hash now 
- lambda layer version is included in the hash (along with other lambda layer attributes)

I also added a few more tests around this area to confirm the current behavior which should help demonstrate what the feature flag will change.

----

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/master/INTEGRATION_TESTS.md)?
	* [ ] 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*
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

@izsherpa
Copy link

izsherpa commented Oct 4, 2022

modify cdk.json to enable this feature, pasting this inside the context:
{...
"context": {
"@aws-cdk/aws-lambda:recognizeLayerVersion": true,
....
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-lambda Related to AWS Lambda bug This issue is a bug. effort/medium Medium work item – several days of effort p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants