JamesMatson
JamesMatson

Reputation: 2922

Can't build .NET Core 3.1 AWS Lambda function using Ubuntu hosted Pipeline in Azure DevOps

I have a previously working Pipeline in Azure DevOps which builds some .NET Core 3.1 AWS Lambda functions. It was using Windows hosted pipeline without issue. I have switched to Ubuntu hosted pipeline to take advantage of the ReadyToRun configuration for Lambda functions. The AWS documentation states that in order to take advantage of this, you must build your code on a Linux agent.

However, with the change to Ubuntu, the pipeline now fails with the below exception:

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.

/usr/bin/dotnet restore
  Determining projects to restore...
  Restored /home/vsts/work/1/s/testapi/LCSApi.csproj (in 6.54 sec).

Beginning Serverless Deployment
Performing package-only build of serverless application, output template will be placed in /home/vsts/work/1/a\serverless-output.yaml
/usr/bin/dotnet lambda package-ci -ot /home/vsts/work/1/a\serverless-output.yaml --region  --s3-bucket --s3-prefix  --disable-interactive true -template serverless.template
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

The step that fails is highlighted below.

enter image description here

I am wondering if it has something to do with the 'since you just installed the .NET Core SDK' message, but not sure how to interpret that, or what it points to in terms of resolving the issue.

EDIT: Quick update, I added a prior task to install the Lambda tools, a bash script with:

/usr/bin/dotnet tool install -g Amazon.Lambda.Tools
/usr/bin/dotnet tool update -g Amazon.Lambda.Tools

So I don't get the 'since you just installed' message, but I still get:

Beginning Serverless Deployment
Performing package-only build of serverless application, output template will be placed in /home/vsts/work/1/a\serverless-output.yaml
/usr/bin/dotnet lambda package-ci -ot /home/vsts/work/1/a\serverless-output.yaml --region  --s3-bucket  --s3-prefix  --disable-interactive true -template serverless.template --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

enter image description here

Upvotes: 0

Views: 1605

Answers (1)

Norm Johanson
Norm Johanson

Reputation: 3177

This is one of the challenges with .NET Core's Global tools is the folder that .NET Core Global tools are installed in is not found in your path. What I would recommend is in your pipeline go straight to the tool instead of using the dotnet CLI. For example change your package-ci command to:

~/.dotnet/tools/dotnet-lambda package-ci -ot /home/vsts/work/1/a\serverless-output.yaml --region  --s3-bucket --s3-prefix  --disable-interactive true -template serverless.template

Upvotes: 2

Related Questions