aws-toolkit-azure-devops icon indicating copy to clipboard operation
aws-toolkit-azure-devops copied to clipboard

Issue building .Net Core 3.1 Package - (potential issues with the home directory?)

Open CheeseNPort opened this issue 4 years ago • 1 comments

I have recently been migrating my .Net API to Core 3.1 in order to take advantage of the ReadyToRun features for quicker cold starts in Lambda as detailed at https://aws.amazon.com/blogs/compute/announcing-aws-lambda-supports-for-net-core-3-1/.

I finished doing migrating all the code and it all builds locally and runs. I updated the task in my pipeline to be as follows.

  • task: LambdaNETCoreDeploy@1 displayName: 'Create Severless API Package' inputs: awsCredentials: AWS command: deployServerless packageOnly: true packageOutputFile: $(Build.ArtifactStagingDirectory)\serverless.template lambdaProjectPath: path/to/project.csproj s3Bucket: 'bucketname' additionalArgs: '--msbuild-parameters "/p:PublishReadyToRun=true --self-contained false'

Looking in the logs, I can see the Amazon Lambda Tools are getting installed here

Since you just installed the .NET Core SDK, you will need to logout or restart your session before running the tool you installed. You can invoke the tool using the following command: dotnet-lambda Tool 'amazon.lambda.tools' (version '4.0.0') was successfully installed.

But then later on it fails with this error

Performing package-only build of serverless application, output template will be placed in /home/vsts/work/1/a\serverless.template /usr/bin/dotnet lambda package-ci -ot /home/vsts/work/1/a\serverless.template --s3-bucket bucketname --disable-interactive true --msbuild-parameters /p:PublishReadyToRun=true --self-contained false Could not execute because the specified command or file was not found. Possible reasons for this include:

  • You misspelled a built-in dotnet command.
  • You intended to execute a .NET Core program, but dotnet-lambda does not exist.
  • You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.

##[error]Error: The process '/usr/bin/dotnet' failed with exit code 1

CheeseNPort avatar May 24 '20 10:05 CheeseNPort

For anyone else struggling with this, my workaround has been to use scripts instead of this task. For me that was...

- script: dotnet tool install --global Amazon.Lambda.Tools --version 4.0.0
        displayName: Instal Amazon.Lambda.Tools
- script: $(HOME)/.dotnet/tools/dotnet-lambda package-ci -o package.zip --template path/to/template --output-template path/to/output/template --disable-interactive true --msbuild-parameters /p:PublishReadyToRun=true --self-contained false --s3-bucket bucket-name --region aws_region --aws-access-key-id ##### --aws-secret-key #####
        displayName: Build Lambda Application for API

CheeseNPort avatar May 29 '20 22:05 CheeseNPort