docker image for deploying serverless dotnet core applications to AWS
1.4K
This is a docker image for deploying dotnet core applications to AWS Serverless(SAM)/Lambda. It should be used as part of a Delivery pipeline, such as through GitLab.
As a bonus, this image uses the official Amazon Linux base image used by AWS Lambda. So you can use it to build targeted/optimized binaries and lambda layers.
To use this docker image manually outside of a CI system, you need to share your aws credentials and solution folder with the container, like so:
Linux Bash:
docker run -it --name amazon -v $HOME/.aws:/root/.aws -v $(pwd):/src carlin/aws-serverless-dotnet-deploy bash
Windows Powershell:
docker run -it --name amazon -v $env:USERPROFILE/.aws:/root/.aws -v $pwd/:/src carlin/aws-serverless-dotnet-deploy bash
You can optimize cold start for your lambda function by publishing your project as optimized runtime binaries:
You will need to modify your csproj file to give optimization instructions to the dotnet compiler. Add these lines to your top <PropertyGroup>:
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<PublishReadyToRun>true</PublishReadyToRun>
Publish the project with the --runtime linux-x64 build flag:
dotnet publish --configuration "Release" --runtime linux-x64 --self-contained false
Note that this build flag is also used to restore nuget packages optimized for linux.
Lambda layers can be used to greatly speed up lambda function boot times, especially for dotnet, as it avoids cold start compilation of binaries for the target platform. They can also be shared between lambda functions, even across your organization's AWS accounts for an extra speed boost; the lambda layer will remain cached as long as it gets used frequently enough to reset the cache expiration.
Use the dotnet lambda publish-layer command from inside the docker container to publish a sharable lambda layer:
dotnet lambda publish-layer your-dotnet-layer --layer-type runtime-package-store --s3-bucket arn:aws:s3:::your-bucket --enable-package-optimization true
Content type
Image
Digest
Size
382.8 MB
Last updated
almost 5 years ago
docker pull carlin/aws-serverless-dotnet-deploy