- Newest
- Most votes
- Most comments
HI
The path you've provided, "/home/vsts/work/1/s/lambda" is likely specific to the Azure DevOps agent environment and may not be the same on your local machine.
Use a relative path Change the path from lambda.Code.fromAsset('/home/vsts/work/1/s/lambda') to lambda.Code.fromAsset('./lambda'). This assumes your lambda code is located in a directory named "lambda" within your CDK project directory. By using a relative path, the CDK will look for the code relative to the location of the CDK script itself.
or Package your lambda code as a zip: You can create a zip file containing your lambda code and then reference the zip file during deployment. This approach can help avoid issues with relative paths. Here's an example: https://stackoverflow.com/questions/73083672/aws-cdk-lambda-function-cannot-find-asset-at-path
JavaScript
const path = require('path');
const lambdaCode = lambda.Code.asset(path.join(__dirname, '../lambda.zip'));
Relevant content
- Accepted Answerasked 2 years ago
- asked 24 days ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 3 years ago
- AWS OFFICIALUpdated 2 years ago
I used the relative path but still the same: Error: Cannot find asset at /home/vsts/work/1/s/lambda at new AssetStaging (/home/vsts/work/1/s/MyCdkProject/node_modules/aws-cdk-lib/core/lib/asset-staging.js:1:2119) at new Asset (/home/vsts/work/1/s/MyCdkProject/node_modules/aws-cdk-lib/aws-s3-assets/lib/asset.js:1:1080) at AssetCode.bind (/home/vsts/work/1/s/MyCdkProject/node_modules/aws-cdk-lib/aws-lambda/lib/code.js:1:4881) at new Function (/home/vsts/work/1/s/MyCdkProject/node_modules/aws-cdk-lib/aws-lambda/lib/function.js:1:9422) at new MyCdkProjectStack (/home/vsts/work/1/s/MyCdkProject/lib/my_cdk_project-stack.js:78:30) at Object.<anonymous> (/home/vsts/work/1/s/MyCdkProject/bin/my_cdk_project.js:6:1) at Module._compile (node:internal/modules/cjs/loader:1369:14) at Module._extensions..js (node:internal/modules/cjs/loader:1427:10) at Module.load (node:internal/modules/cjs/loader:1206:32) at Module._load (node:internal/modules/cjs/loader:1022:12)
Node.js v20.12.2
Subprocess exited with error 1 ##[error]Error: The process '/usr/bin/bash' failed with exit code 1 Finishing: Deploy CDK stack