Reputation: 31
We had a .NET code with version 6.0 residing in AWS Code Commit. We are trying to build the .NET code using AWS Windows code built in the Windows environment. Once the postcode is built, we need to pack the built code, and the generated APIs should be deployed to AWS Lambda. Previously we were doing all this build and deployment locally using manual steps with the AspNetCore.2.0.9
& dotnet-sdk-2.1.202
versions also installed. For this, we are using commands in our local after cloning repo.
dotnet restore
dotnet lambda package --configuration release --framework net6.0 --output-package bin/release/net6.0/hello.zip
. After the zip is created, we use using following command to deploy the code to Lambdacd Test
sls deploy -r us-east-1 -s <stage> -v
To automate this, we created a code build and code pipeline. For Code build following is the Buildspec we used and unable to achieve this through the pipeline and getting errors while building. Attached is the Buildspec and the errors below.
Build spec:
version: 0.2
phases:
install:
commands:
- Echo "Installing required versions of .Net.."
- dotnet --version
- Invoke-WebRequest -Uri https://dot.net/v1/dotnet-install.ps1 -OutFile dotnet-install.ps1
- .\dotnet-install.ps1 -Channel STS
- $env:PATH = $env:PATH + ";$env:USERPROFILE\.dotnet"
- Echo "Installation completed..!"
pre_build:
commands:
- echo "Entering pre_build phase.."
- dotnet new install Amazon.Lambda.Templates::*
- dotnet new install Amazon.Lambda.Tools
- dotnet new install Amazon.Lambda.TestTool-3.1
- dotnet new install Microsoft.DotNet.Web.Spa.ProjectTemplates
- echo "Pre_build phase Completed..!"
build:
commands:
- echo "Running build commands now.."
- cmd /c build.cmd
- echo "Build completed now..!"
post_build:
commands:
- ls "bin/release/net6.0"
artifacts:
files:
#- '**/*'
Error:-
[Container] 2023/09/05 09:05:17 Running command cmd /c build.cmd
C:\codebuild\tmp\output\src644877321\src\git-codecommit.us-east-1.amazonaws.com\v1\repos\test_API>dotnet restore
Determining projects to restore...
Restored C:\codebuild\tmp\output\src644877321\src\git-codecommit.us-east-1.amazonaws.com\v1\repos\test_API\testAPI.csproj (in 12.35 sec).
Restored C:\codebuild\tmp\output\src644877321\src\git-codecommit.us-east-1.amazonaws.com\v1\repos\test_API\test_API.csproj (in 13.7 sec).
C:\codebuild\tmp\output\src644877321\src\git-codecommit.us-east-1.amazonaws.com\v1\repos\test_API>dotnet lambda package --configuration release --framework net6.0 --output-package bin/release/net6.0/hello.zip
You must install or update .NET to run this application.
App: C:\Users\ContainerAdministrator\.nuget\packages\amazon.lambda.tools\2.2.0\lib\netcoreapp2.0\dotnet-lambda.dll
Architecture: x64
Framework: 'Microsoft.NETCore.App', version '2.0.0' (x64)
.NET location: C:\Program Files\dotnet\
The following frameworks were found:
3.1.32 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
6.0.13 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
7.0.2 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Learn about framework resolution:
https://aka.ms/dotnet/app-launch-failed
To install missing framework, download:
https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=2.0.0&arch=x64&rid=win10-x64
[Container] 2023/09/05 09:05:40 Command did not exit successfully cmd /c build.cmd exit status 0x80008096
[Container] 2023/09/05 09:05:41 Phase complete: BUILD State: FAILED
[Container] 2023/09/05 09:05:41 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: cmd /c build.cmd. Reason: exit status 0x80008096
Upvotes: 3
Views: 149