The long awaited support for .NET Core 3.1 on AWS Lambda has finally been released. My Twitter bot runs on .NET Core 2.1 in a Lambda function and I have been meaning to update it to .NET Core 3.1 since the beginning. So let’s do just that!
I’ll be following the steps on the announcement blog post to migrate to 3.1.
First up, the
TargetFrameowrk in the project file (csproj) needs to be updated, so let’s do that:
runtime also needs to be updated in my CloudFormation template:
I’m using AWS CodeBuild for CI, and I should also update the .NET version that is used to build the app:
Note: I had to update my CodeBuild image to
aws/codebuild/standard:4.0 as this is the version they added support for 3.1 in. See this comment for more details.
The last step for my project is to update any NuGet packages to the latest versions. For that, I’ll use the very helpful .NET Tool
dotnet-outdated, which can automatically update package versions for you:
$ dotnet-outdated src/DotNetTwitterBot/DotNetTwitterBot.csproj -u
AWSSDK.SecretsManager 22.214.171.124 -> 126.96.36.199
Version color legend:
<red> : Major version update or pre-release version. Possible breaking changes.
<yellow>: Minor version update. Backwards-compatible features added.
<green> : Patch version update. Backwards-compatible bug fixes.
Upgrading package AWSSDK.SecretsManager...
Project DotNetTwitterBot [.NETCoreApp,Version=v3.1] upgraded successfully
There are lots of new features that come with .NET Core 3.1 that can be utilised in AWS Lambda, such as:
- New Lambda JSON serializer
- ReadyToRun for better cold start performance
- Updated AWS Mock .NET Lambda Test Tool
But, I thought to leave these for other blog posts.
Cool! That’s it for my app then. Let’s merge this into master and see how it goes!
In this post, we updated my Twitter bot app from .NET Core 2.1 to 3.1. This was pretty straight forward, just updating a the version in a few files and updating some NuGet packages. It was a very painless exercise and I recommend everyone do it for their apps; there’s lots of performance improvements in 3.1 so if all of our code runs faster, that hopefully a lot of CO2 we could be saving!