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: cdk destroy requires the deployment asset #20060

Open
bdruth opened this issue Apr 24, 2022 · 10 comments · May be fixed by #33323
Open

aws-lambda: cdk destroy requires the deployment asset #20060

bdruth opened this issue Apr 24, 2022 · 10 comments · May be fixed by #33323
Labels
@aws-cdk/aws-lambda Related to AWS Lambda bug This issue is a bug. effort/small Small work item – less than a day of effort p1 package/tools Related to AWS CDK Tools or CLI

Comments

@bdruth
Copy link

bdruth commented Apr 24, 2022

Describe the bug

Running cdk destroy with a Lambda function asset requires the deployment asset to be present. This seems counterintuitive at best and problematic in a variety of situations.

Expected Behavior

cdk destroy should succeed, tear down the CF stack, undeploy the Lambda, etc. - no deployment asset should be needed.

Current Behavior

2022-04-24.14:07:28 [STEP 1: Destroy the app] Destroying the application

/example-repo/environment/lambda/node_modules/aws-cdk-lib/core/lib/asset-staging.ts:165
      throw new Error(`Cannot find asset at ${this.sourcePath}`);
            ^
Error: Cannot find asset at /example-repo/environment/lambda/build/distributions/lambda-0.1.0-SNAPSHOT.zip
    at new AssetStaging (/example-repo/environment/lambda/node_modules/aws-cdk-lib/core/lib/asset-staging.ts:165:13)
    at new Asset (/example-repo/environment/lambda/node_modules/aws-cdk-lib/aws-s3-assets/lib/asset.ts:131:21)
    at AssetCode.bind (/example-repo/environment/lambda/node_modules/aws-cdk-lib/aws-lambda/lib/code.ts:282:20)
    at new Function (/example-repo/environment/lambda/node_modules/aws-cdk-lib/aws-lambda/lib/function.ts:699:29)
    at new LambdaStack (/example-repo/environment/lambda/lib/lambda-stack.ts:10:21)
    at Object.<anonymous> (/example-repo/environment/lambda/bin/lambda.ts:7:1)

Reproduction Steps

  1. cdk deploy a stack that uses a Lambda asset
  2. delete the asset
  3. cdk destroy the stack

Possible Solution

Don't look for the asset when destroying.

Additional Information/Context

Using CDK TypeScript to deploy a Java Lambda asset

CDK CLI Version

2.20.0 (build 738ef49)

Framework Version

?

Node.js Version

v16.14.2

OS

Ubuntu 20.04.4 LTS

Language

Typescript

Language Version

TypeScript (~3.9.7)

Other information

No response

@bdruth bdruth added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Apr 24, 2022
@github-actions github-actions bot added the @aws-cdk/aws-lambda Related to AWS Lambda label Apr 24, 2022
@ryparker ryparker added the p2 label Apr 26, 2022
@peterwoodworth peterwoodworth removed the needs-triage This issue or PR still needs to be triaged. label Apr 27, 2022
@sawden
Copy link

sawden commented Jun 21, 2022

any updates on this?

@rjminchuk
Copy link

👀

1 similar comment
@SenorMann
Copy link

👀

@kaizencc kaizencc added package/tools Related to AWS CDK Tools or CLI effort/small Small work item – less than a day of effort labels Aug 24, 2022
@kaizencc kaizencc removed their assignment Aug 24, 2022
@kaizencc
Copy link
Contributor

Labeling this as p2 which means the CDK team doesn't have this fix on our immediate roadmap. However, we'd love to see a community contribution on this!

@Russ-K
Copy link

Russ-K commented Oct 24, 2022

This also affects aws_s3_deployment.BucketDeployment

elenavanengelenmaslova pushed a commit to elenavanengelenmaslova/the-christmas-challenge that referenced this issue Dec 23, 2022
@jgoux
Copy link

jgoux commented Jun 21, 2023

I just got the error as well for the bucket deployment construct. Happy to contribute if I'm pointed to the relevant code!

@connelhooley
Copy link

I just got the error as well for the bucket deployment construct. Happy to contribute if I'm pointed to the relevant code!

I have the following working for BucketDeployment (TypeScript):

if (Stack.of(this).bundlingRequired) {
  new BucketDeployment(this, "DeployWebsite", {
    sources: [Source.asset(path.join(__dirname, "../../dist"))],
    destinationBucket: bucket,
  });
}

This seems to get around the issue for that, but Functions are more awkward as the deployment and resource are in one item.

@connelhooley
Copy link

Hmm the following is awful but seems to work:

const createFunction = new Function(this, "CreateFunction", {
  functionName: `CoolNameForFunction`,
  code: Stack.of(this).bundlingRequired
    ? Code.fromAsset(path.join(__dirname, "../../dist"))
    : Code.fromInline(";"), // Can't put an empty string
  runtime: Runtime.NODEJS_18_X,
  handler: "create-func.handler",
});

Copy link

This issue has received a significant amount of attention so we are automatically upgrading its priority. A member of the community will see the re-prioritization and provide an update on the issue.

@github-actions github-actions bot added p1 and removed p2 labels Aug 18, 2024
@4dhyperplane
Copy link

Any updates on this one?

@sumupitchayan sumupitchayan self-assigned this Sep 30, 2024
@IkeNefcy IkeNefcy linked a pull request Feb 6, 2025 that will close this issue
1 task
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/small Small work item – less than a day of effort p1 package/tools Related to AWS CDK Tools or CLI
Projects
None yet
Development

Successfully merging a pull request may close this issue.