AWS Developer Blog

.NET Core 2.1 and AWS

We’re excited about the recently released .NET Core 2.1, and we’re sure many of our AWS .NET developers are also eager to get started with .NET Core 2.1. Look forward to future announcements from us as we get our AWS services, such as AWS Elastic Beanstalk, AWS Lambda, and AWS CodeBuild, updated for .NET Core 2.1.

Getting Started Today

While we get our AWS services updated for .NET Core 2.1, you can use .NET Core 2.1 today on most AWS services with just a couple more steps.

Using .NET Core 2.1 with Containers

The .NET Team at Microsoft has published new docker base images for .NET Core 2.1 (https://hub.docker.com/r/microsoft/dotnet/). You can use these in any of the AWS container-based services. For AWS CodeBuild, use one of the images with “sdk” in the tag name. These images contain all of the necessary tools to build your .NET Core application.

You can execute your .NET Core application on Amazon Elastic Container Service (Amazon ECS). When building your docker image for Amazon ECS, choose images with “runtime” in the tag name to create smaller container images. If you are deploying an ASP.NET Core application then choose an image with “aspnetcore-runtime” in the tag name which will include the ASP.NET Core framework. These runtime images enable you to improve startup time and can allow you to run a denser cluster with smaller images. If you’ve never deployed a .NET Core container application to AWS, our AWS Guide for .NET Developers can help you get started.

Deploying ASP.NET Core 2.1 Applications with AWS Elastic Beanstalk

One of the great strengths of the .NET Core platform is its ability to publish as a self-contained application. This means that although the Elastic Beanstalk environments aren’t updated yet with .NET Core 2.1, we can direct the .NET Core publish mechanism to do a self-contained publish and the .NET Core 2.1 runtime will be included with the publish bundle.

To turn on the self-contained publish mode for an ASP.NET Core project, you need to edit your .csproj file and add a property that sets the RuntimeIdentifier to win-x64. Setting it to win-x64 tells the dotnet publish command, which the AWS Toolkit for Visual Studio uses, to include the 64-bit Windows .NET Core runtime.


<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>
    <RuntimeIdentifier>win-x64</RuntimeIdentifier>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.App" />
  </ItemGroup>

  <ItemGroup>
    <DotNetCliToolReference Include="Amazon.ElasticBeanstalk.Tools" Version="1.1.3" />
  </ItemGroup>
</Project>

In the .csproj file above, notice a DotNetCliToolReference to Amazon.ElasticBeanstalk.Tools. This is a dotnet CLI extension we created, similar to our AWS Lambda extension, that enables you to perform your Elastic Beanstalk deployments from the dotnet CLI. In version 1.1.4, there’s a new –publish-options switch that enables you to pass parameters to the underlying call to dotnet publish. By using this, you can do a self-contained publish without even modifying your .csproj file. Here is an example of initiating a self-contained deployment.

dotnet eb deploy-environment --publish-options "--runtime win-x64"

For more information about this and about AWS Lambda and Amazon ECS dotnet CLI extensions, check out the GitHub repository.

Stay Connected

We’ll have more announcements as we get AWS services updated to .NET Core 2.1. Be sure to follow our AWS Developer Blog for .NET and our AWS SDK for .NET Twitter handle (@awsfornet) for the latest news coming from our team.