Improving Lambda Custom Runtime Cold Start and Deployment Speeds with .NET 6

Full source code available here

This post builds [on the previous] where I showed how to build a Lambda with .NET 6 on Arm 64. That one walked through all the steps to create the .NET 6 project, and deploy the Lambda.

In this post I’m going to briefly talk about two features in .NET that help with Lambda cold start and deployment speeds, these are Publish Trimmed, and ReadyToRun.

Publish Trimmed reduces the size of the package that is deployed by removing unused parts of libraries that would otherwise be included. ReadyToRun performs an ahead of time compilation, reducing startup delays.

These changes are only needed when using the custom runtime, when the managed runtime for .NET 6 is available on Lambda, you won’t need to make these changes.

Changes to the .csproj file

To enable these features open the .csproj file, and add the following to the PropertyGroup -


Then redeploy the Lambda by running dotnet lambda deploy-function YourLambda.

In the case of my .NET 6 Arm 64 application from the previous post, my initial package deployment size was 43.2 MB, with the PublishTrimmed option enabled, it is down to 27.1 MB, and my cold start times improved by about 30%, but don’t take this number to the bank.

Not bad for two lines of configuration, and of course all the work of the .NET 6 team, thank you!

Full source code available here

comments powered by Disqus