Cannot deploy Lambda through CI pipeline in Azure Devops

0

Enter image description here I want to try to deploy a simple AWS stack with a VPC,Security groups and a Lambda through a pipeline in Azure Devops. I always get this error: Error: Cannot find asset at /home/vsts/work/1/s/lambda If I try to deploy directly from VSO using cdk deploy everything works fine. I have tried everything like : code: lambda.Code.fromAsset(path.join(__dirname, '../lambda')),

but no luck.

Any suggestions?

This is the code I have for creating the Lambda:

  • //create the Lambda Function with properties const myLambdaFunction = new lambda.Function(this, 'MyFunction', { runtime: lambda.Runtime.NODEJS_16_X, // Lambda runtime environment code: lambda.Code.fromAsset('lambda'), // Code loaded from the "lambda" directory handler: 'index.handler', // File is "index.js", function is "handler" memorySize: 128, // Optional configuration timeout: cdk.Duration.seconds(30), // Maximum execution time role: lambdaRole, // Set the custom role for this Lambda vpc: vpc, securityGroup: securityGroup1 });*

The structure that I have in my project can be viewed from the photo that I have uploaded.

gefragt vor einem Monat120 Aufrufe
1 Antwort
0

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'));
profile picture
EXPERTE
GK
beantwortet vor einem Monat
profile picture
EXPERTE
überprüft vor einem Monat
  • 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

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen