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

Code.fromAsset("...") is not updating lambda-functions #7669

Closed
ghost opened this issue Apr 29, 2020 · 8 comments
Closed

Code.fromAsset("...") is not updating lambda-functions #7669

ghost opened this issue Apr 29, 2020 · 8 comments
Assignees
Labels
@aws-cdk/aws-lambda Related to AWS Lambda bug This issue is a bug.

Comments

@ghost
Copy link

ghost commented Apr 29, 2020

Description

When I create a lambda-function within a cdk-stack based on Code.fromAsset("dist", { exclude: ["**", "!lambda-already-bundled-with-webpack.js"] }), then the lambda-function, when deployed for the first time, works fine. But when a code-update to the lambda-function is made, a re-deploy of the same cdk-stack is not updating the code of the deployed lambda-function. The lambda-function still has the old code from the first deployment. A cdk diff also says that no changes were detected...

Reproduction Steps

Error Log

Environment

  • **CLI Version :1.35.0
  • **Framework Version:1.35.0
  • **OS :macOS Catalina 10.15.4
  • **Language :typescript

Other


This is 🐛 Bug Report

@ghost ghost added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Apr 29, 2020
@SomayaB SomayaB added the @aws-cdk/aws-lambda Related to AWS Lambda label Apr 30, 2020
@NetaNir
Copy link
Contributor

NetaNir commented May 1, 2020

Hi!

Can you provide the full code?
The bellow code generates a different parameter name based on the hash of the lambda folder content. A change to the content of the lambda folder will result in a different hash value, producing a different parameter name, triggering a deployment.

    const fn = new lambda.Function(this, 'MyLambda', {
      code: lambda.Code.fromAsset(path.join(__dirname, './lambda')),
      handler: 'index.handler',
      runtime: Runtime.NODEJS_12_X
    });

Do you see the same parameters name produced when you change the content of the dist folder?

@jogold
Copy link
Contributor

jogold commented May 1, 2020

Looks like #7718

@ghost
Copy link
Author

ghost commented May 1, 2020

@NetaNir @jogold Thank you for your input.

Here is my code:

const myFunction = new lambda.Function(this, "myFunction", {
  code: lambda.Code.fromAsset("dist", { exclude: ["**", "!my-function.js"] }),
  handler: "my-function.entrypoint",
  runtime: lambda.Runtime.NODEJS_12_X,
});

The reason why I use an exclude pattern here is, that I am outputting multiple lambda-functions to dist. Is the usage of an exclude-pattern not recommended at the moment?

@nija-at
Copy link
Contributor

nija-at commented May 13, 2020

@Syy0n - sorry for the late reply, but can you also provide your directory structure?

Specifically the output of tree when run in the folder dist.

@nija-at nija-at added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed needs-triage This issue or PR still needs to be triaged. labels May 13, 2020
@ghost
Copy link
Author

ghost commented May 14, 2020

@nija-at The output is:

.
├── create-lambda-bundle.js
├── create-lambda.js
├── dtos
│   ├── create-dto.js
│   └── get-dto.js
├── entities
│   └── customer.js
├── get-lambda-bundle.js
├── get-lambda.js
└── service.js

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label May 14, 2020
@nija-at
Copy link
Contributor

nija-at commented May 15, 2020

I just tried your example and it worked fine for me.

The CDK app I used -

import { Function, Code, Runtime } from '@aws-cdk/aws-lambda';
import { App, Stack } from '@aws-cdk/core';

const app = new App();
const stack = new Stack(app, 'mystack-lambda');

new Function(stack, 'myfn', {
  runtime: Runtime.NODEJS_12_X,
  handler: 'index.handler',
  code: Code.fromAsset('resources', {
    exclude: [ '**', '!a.js']
  })
})

The resources/ folder looks like this -

⇒  tree resources
resources
├── a.js
├── b.js
└── fs
    └── c.js

1 directory, 3 files

and the asset folder looks like this -

⇒  tree cdk.out/asset.612208983ad862413ed9c910ace722035cd862a55d2b8d203a2e04c7538ea257
cdk.out/asset.612208983ad862413ed9c910ace722035cd862a55d2b8d203a2e04c7538ea257
└── a.js

0 directories, 1 file

I believe this matches what was intended with the exclude option.

@nija-at nija-at added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label May 15, 2020
@jogold
Copy link
Contributor

jogold commented May 15, 2020

I think that this was #7718 that has been fixed in v1.38.0.

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label May 15, 2020
@nija-at
Copy link
Contributor

nija-at commented May 15, 2020

Nice. Thanks @jogold. Resolving this issue.

Feel free to re-open with more details if it persists.

@nija-at nija-at closed this as completed May 15, 2020
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.
Projects
None yet
Development

No branches or pull requests

4 participants