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-python-alpha: Bundling - AssetHashType.OUTPUT failing cdk destroy #26345

Open
edwardgale opened this issue Jul 13, 2023 · 5 comments
Labels
@aws-cdk/aws-lambda-python bug This issue is a bug. effort/medium Medium work item – several days of effort p2

Comments

@edwardgale
Copy link

Describe the bug

RuntimeError: Cannot use output hash type when bundling is not specified.

cdk destroy and cdk destroy --no-staging both failing because we have the following bundling options for our lambda:

lambda_alpha.BundlingOptions(
            asset_excludes=exclusions,
            asset_hash_type=AssetHashType.OUTPUT,
            volumes=[
                DockerVolume(
                    host_path=lib_dir,
                    container_path="/asset-input/lib",
                )
            ],
        )

We create the hash on the Output because our exclusions list is large and some files in the exclusions list are dynamic leading to changes in hash and unnecessary redeployments.

Expected Behavior

cdk destroy and cdk destroy --no-staging should destroy the stack. Creating a hash type of OUTPUT has no relevance here.

Current Behavior

The following stack trace was emitted:

jsii.errors.JavaScriptError: 
  Error: Cannot use `output` hash type when `bundling` is not specified.
      at AssetStaging.calculateHash (/private/var/folders/88/x7htgmyn7cz9ldg_w22npf_m0000gn/T/jsii-kernel-MJTiCj/node_modules/aws-cdk-lib/core/lib/asset-staging.js:2:1509)
      at AssetStaging.stageByCopying (/private/var/folders/88/x7htgmyn7cz9ldg_w22npf_m0000gn/T/jsii-kernel-MJTiCj/node_modules/aws-cdk-lib/core/lib/asset-staging.js:1:3148)
      at stageThisAsset (/private/var/folders/88/x7htgmyn7cz9ldg_w22npf_m0000gn/T/jsii-kernel-MJTiCj/node_modules/aws-cdk-lib/core/lib/asset-staging.js:1:2065)
      at Cache.obtain (/private/var/folders/88/x7htgmyn7cz9ldg_w22npf_m0000gn/T/jsii-kernel-MJTiCj/node_modules/aws-cdk-lib/core/lib/private/cache.js:1:242)
      at new AssetStaging (/private/var/folders/88/x7htgmyn7cz9ldg_w22npf_m0000gn/T/jsii-kernel-MJTiCj/node_modules/aws-cdk-lib/core/lib/asset-staging.js:1:2400)
      at new Asset (/private/var/folders/88/x7htgmyn7cz9ldg_w22npf_m0000gn/T/jsii-kernel-MJTiCj/node_modules/aws-cdk-lib/aws-s3-assets/lib/asset.js:1:736)
      at AssetCode.bind (/private/var/folders/88/x7htgmyn7cz9ldg_w22npf_m0000gn/T/jsii-kernel-MJTiCj/node_modules/aws-cdk-lib/aws-lambda/lib/code.js:1:4628)
      at new Function (/private/var/folders/88/x7htgmyn7cz9ldg_w22npf_m0000gn/T/jsii-kernel-MJTiCj/node_modules/aws-cdk-lib/aws-lambda/lib/function.js:1:7479)
      at new PythonFunction (/private/var/folders/88/x7htgmyn7cz9ldg_w22npf_m0000gn/T/jsii-kernel-MJTiCj/node_modules/@aws-cdk/aws-lambda-python-alpha/lib/function.js:40:9)
      at Kernel._create (/private/var/folders/88/x7htgmyn7cz9ldg_w22npf_m0000gn/T/tmpc8zaccia/lib/program.js:9964:29)

Reproduction Steps

Create a python lambda function with the following options:

        lambda_alpha.PythonFunction(
            self,
            "MyFunc",
            entry="/path/to/src",
            index="app.py",
            handler="lambda_handler",
            bundling=lambda_alpha.BundlingOptions(
                asset_hash_type=AssetHashType.OUTPUT,
            ),
            runtime = lambda_.Runtime.PYTHON_3_10
        )

deploy and run cdk destroy --no-staging

Possible Solution

Logic contained within

throw new Error(`Cannot use \`${hashType}\` hash type when \`bundling\` is not specified.`);

Additional Information/Context

No response

CDK CLI Version

2.85.0 (build 4e0d726)

Framework Version

No response

Node.js Version

v18.16.0

OS

MacOs 13.4.1 (c)

Language

Python

Language Version

No response

Other information

No response

@edwardgale edwardgale added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jul 13, 2023
@pahud
Copy link
Contributor

pahud commented Jul 13, 2023

RuntimeError: Cannot use output hash type when bundling is not specified.

I didn't get it. According your repro steps, you actually provided the bundling prop, didn't you?

lambda_alpha.PythonFunction(
            self,
            "MyFunc",
            entry="/path/to/src",
            index="app.py",
            handler="lambda_handler",
            bundling=lambda_alpha.BundlingOptions(
                asset_hash_type=AssetHashType.OUTPUT,
            ),
            runtime = lambda_.Runtime.PYTHON_3_10
        )

@pahud pahud added p2 effort/medium Medium work item – several days of effort 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 Jul 13, 2023
@github-actions
Copy link

This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

@github-actions github-actions bot added the closing-soon This issue will automatically close in 4 days unless further comments are made. label Jul 16, 2023
@edwardgale
Copy link
Author

edwardgale commented Jul 17, 2023

Bundling prop was provided. However asset_hash_type=AssetHashType.OUTPUT still fails a cdk destroy

Very basic repo to reproduce the issue here:

https://github.com/edwardgale/cdk-destroy-issue

@github-actions github-actions bot removed closing-soon This issue will automatically close in 4 days unless further comments are made. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. labels Jul 17, 2023
@mikey-
Copy link

mikey- commented Jul 24, 2023

Seeing this with node functions on deploy as well btw. lmk if more info is required or you'd prefer it in another issue <3 ty

@sercantor
Copy link

Still getting this

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

No branches or pull requests

4 participants