Can't package lambda for .NET 7 AOT from within a Docker Container
See original GitHub issueDescribe the bug
Our CI build pipelines all run inside docker contains so that we can easily control versions of the toolkits that we are using.
It seems that the newest version of the Lambda build tookit tries to start up it’s own docker container which doesn’t seem to work very well when running already from within docker. This has worked great up until now, but the .NET 7 process seems to have broken.
Starting container for native AOT build using build image: public.ecr.aws/sam/build-dotnet7:latest-x86_64.
Unknown error executing command: Failed to locate docker CLI executable. Make sure the docker CLI is installed in the environment PATH.
at Amazon.Common.DotNetCli.Tools.DockerCLIWrapper..ctor(IToolLogger logger, String workingDirectory) in C:\build\src\Amazon.Common.DotNetCli.Tools\DockerCLIWrapper.cs:line 23
at Amazon.Lambda.Tools.LambdaPackager.CreateApplicationBundle(LambdaToolsDefaults defaults, IToolLogger logger, String workingDirectory, String projectLocation, String configuration, String targetFramework, String msbuildParameters, String architecture, Boolean disableVersionCheck, LayerPackageInfo layerPackageInfo, Boolean isNativeAot, Nullable`1 useContainerForBuild, String containerImageForBuild, String codeMountDirectory, String& publishLocation, String& zipArchivePath) in C:\build\src\Amazon.Lambda.Tools\LambdaPackager.cs:line 144
at Amazon.Lambda.Tools.Commands.PackageCommand.PerformActionAsync() in C:\build\src\Amazon.Lambda.Tools\Commands\PackageCommand.cs:line 231
at Amazon.Common.DotNetCli.Tools.Commands.BaseCommand`1.ExecuteAsync() in C:\build\src\Amazon.Common.DotNetCli.Tools\Commands\BaseCommand.cs:line 47
Process exited with code 255
Process exited with code 255 (Step: Command Line)
Step Command Line failed
Expected Behavior
The Amazon.Lambda.Tools
toolkit can be ran from within a docker container
Current Behavior
the dotnet lambda package
command crashes when ran in docker
Reproduction Steps
- Create a .NET 7 lambda project using AOT following this AWS guide
- docker run -v ${PWD}:/build -it mcr.microsoft.com/dotnet/sdk:7.0 sh
apt-get update && apt-get -y install zip
dotnet tool install -g Amazon.Lambda.Tools
export PATH="$PATH:/root/.dotnet/tools"
dotnet lambda package -pl build/Examples.AWS.Lambda.S3
Resulting Error
Amazon Lambda Tools for .NET Core applications (5.6.2)
Project Home: https://github.com/aws/aws-extensions-for-dotnet-cli, https://github.com/aws/aws-lambda-dotnet
Found /etc/os-release
Architecture not provided, defaulting to x86_64 for container build image.
Executing publish command
Starting container for native AOT build using build image: public.ecr.aws/sam/build-dotnet7:latest-x86_64.
Unknown error executing command: Failed to locate docker CLI executable. Make sure the docker CLI is installed in the environment PATH.
at Amazon.Common.DotNetCli.Tools.DockerCLIWrapper..ctor(IToolLogger logger, String workingDirectory) in C:\build\src\Amazon.Common.DotNetCli.Tools\DockerCLIWrapper.cs:line 23
at Amazon.Lambda.Tools.LambdaPackager.CreateApplicationBundle(LambdaToolsDefaults defaults, IToolLogger logger, String workingDirectory, String projectLocation, String configuration, String targetFramework, String msbuildParameters, String architecture, Boolean disableVersionCheck, LayerPackageInfo layerPackageInfo, Boolean isNativeAot, Nullable`1 useContainerForBuild, String containerImageForBuild, String codeMountDirectory, String& publishLocation, String& zipArchivePath) in C:\build\src\Amazon.Lambda.Tools\LambdaPackager.cs:line 144
at Amazon.Lambda.Tools.Commands.PackageCommand.PerformActionAsync() in C:\build\src\Amazon.Lambda.Tools\Commands\PackageCommand.cs:line 231
at Amazon.Common.DotNetCli.Tools.Commands.BaseCommand`1.ExecuteAsync() in C:\build\src\Amazon.Common.DotNetCli.Tools\Commands\BaseCommand.cs:line 47
Possible Solution
Consider not trying to spin up docker containers if the tool is already running in docker?
Additional Information/Context
No response
Targeted .NET platform
.NET 7
CLI extension version
amazon.lambda.tools 5.6.2
Environment details (OS name and version, etc.)
mcr.microsoft.com/dotnet/sdk:7.0 sh
Issue Analytics
- State:
- Created 10 months ago
- Comments:10 (6 by maintainers)
Top Results From Across the Web
Build Failure For .NET 7 AOT When Using A Private ...
Describe the bug I've been following this AWS article to build a Lambda function target .net 7 AOT. I've a test function here....
Read more >Running a .NET AWS Lambda locally in a Docker container
I'm having trouble running my .NET 7 Lambda locally as a Docker container. There seems to be loads online about running python or...
Read more >Deploy .NET Lambda functions with container images
Deploy your .NET Lambda function code as a container image using an AWS provided base image or the runtime interface client.
Read more >Using .NET 7 native AOT with AWS Lambda - YouTube
NET 7 today with AWS Lambda, and reduce your cold starts by taking ... AOT ) compilation to deploy your lambda functions as...
Read more >.NET 7 on AWS Lambda with NativeAOT - YouTube
In this video you will learn how you can use . NET on AWS Lambda using Native Ahead of Time Compilation. AWS Lambda...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@Hammatt To your question on will there be a managed .NET 7 runtime, Lambda’s policy is to only support LTS versions for managed runtimes. So for .NET 7 the options are to deploy as a self contained or native aot function to the the
provided.al2
runtime.@Hammatt Adding configuration to @ashishdhingra statement if the CLI tooling detects it is running in an AL2 environment like an AL2 container then it won’t try spin up a container. The tough part of the dev cycle of Native AOT is the .NET code needs to compiled on the same OS as where it will run so spinning up a container was our best option when packaging on a non-AL2 environment.