AWS Elastic Beanstalk adds .NET Core on Linux platform

Today the AWS Elastic Beanstalk service extends its .NET support with the creation of the new .NET Core on Linux platform. This new platform version makes it easy to get ASP.NET Core applications deployed to AWS quickly for either a dev stack or a full production environment including enhanced health, patching, autoscaling, and rolling deployments.

Cost savings with .NET Core on Linux platform

The new .NET Core on Linux platform has significant cost savings compared to existing .NET on Windows Server platform. For example, For example, using the .NET Core on Linux platform on a t3.medium instance type to using the .NET on Windows Server platform on a t3.medium instance type in the us-east-1 AWS region, you can get 30% cost savings with on-demand pricing. Also, when using .NET Core on Linux platform, you can often use smaller EC2 instance types to handle your .NET workloads providing even greater cost savings.

Differences between Windows and Linux platforms

Besides the OS platform version differences there are a couple other differences to be aware of when using the new .NET Core on Linux platform. First, Nginx is used as a reverse proxy to the Kestrel webserver hosting the ASP.NET Core application. For applications that need Kestrel to be the internet-facing webserver it is possible to disable Nginx. We’ll talk about how to do that later.

The other major difference is the package bundle. With a Windows Server platform a separate manifest file must be included with the deployment bundle to configure IIS with the ASP.NET Core application. For the new .NET Core on Linux platform, the deployment bundle can be as simple as a zip file of the output from the dotnet publish command. For more advanced use cases like running multiple ASP.NET Core applications within the same Elastic Beanstalk environment a Procfile can be included in the deployment bundle, listing all of the processes you want to run as a service in the environment.

Getting started

If you have never used Elastic Beanstalk before there are a couple terms you should know to help you get started. First, there is an application, which is the logical grouping of all of the deployed instances of your applications. Within applications you have a collection of environments. Environments are the actual AWS resources that are running your application. When you create an environment you choose a platform version to base the environment on, like the new .NET Core on Amazon Linux 2 v1.0.0 platform version released today.

Depending on your developer workflow there are many ways to get started. Here are some of the most common ways for developers getting started with Elastic Beanstalk.

Console

In the Elastic Beanstalk console you can get started by creating new environment. In the Platform section select the new .NET Core on Linux Platform.

AWS console platform selector

To use your application in the new environment, first execute the dotnet publish command from the command line in your project directory. Once the publish command is complete, zip up the contents of the publish folder and upload that to the environment.

Visual Studio

Starting with version 1.18.0.0 of the AWS Toolkit for Visual Studio you can publish your application to the new .NET Core on Linux platform. To start publishing your application, right click on your project in the solution explorer and select Publish to AWS Elastic Beanstalk.

AWS Explore in AWS Toolkit for Visual Studio

The wizard will walk you through creating a new Elastic Beanstalk environment and creating the deployment bundle for the environment based on how you want to run the application. To indicate you want to deploy to .NET Core on Linux platform, select the 64bit Amazon Linux 2 v1.0.0 running .NET Core platform version.

Visual Studio deployment wizard platform selector

As mentioned earlier, Nginx is used as the reverse proxy by default in Elastic Beanstalk. On the Application Options page of the wizard you can change the Reverse Proxy setting to *none* to use Kestrel as the internet-facing webserver.

AWS Options page reverse proxy settings

Once you finish the wizard your application will be built and packaged for Elastic Beanstalk, and then the environment will be created to host your application. To deploy new versions of your application select the environment you previously created. Depending on how you configure deployments for your environment, you can perform quick redeployments for dev environments, or perform slower, rolling, deployments for production environments. Check the Elastic Beanstalk developer guide for more information on deployment strategies.

Command line

Like the pattern we used with .NET Core for Lambda all of the deployment tooling we integrated inside Visual Studio for deploying .NET Core application to Elastic Beanstalk can also be used on the command line using the Amazon.ElasticBeanstalk.Tools .NET Core Global Tool. To install the tool execute the following command.


dotnet tool install -g Amazon.ElasticBeanstalk.Tools

Then in the project directory execute the following command to deploy the application to Elastic Beanstalk.


dotnet eb deploy-environment

You can either specify the required parameters on the command line or the the tool will query you while it is performing the deployment. If you first deployed using the AWS Toolkit for Visual Studio it will create a file called aws-beanstalk-tools-defaults.json in the project directory with all of the settings made in the wizard saved to the file. Then when you attempt to deploy from the command line using Amazon.ElasticBeanstalk.Tools it will use the values stored in aws-beanstalk-tools-defaults.json making it easy to transition from deploying in Visual Studio to the command line and integrating into your automation.

Here is an example of deploying from scratch to Elastic Beanstalk using Amazon.ElasticBeanstalk.Tools.

Example CLI deployment

Trying out .NET 5 preview in Elastic Beanstalk

The AL2 platform launches with support for .NET Core 2.1 and 3.1. You can also deploy any version of .NET Core as a self contained deployment bundle. That includes .NET 5 which is currently in preview. In the AWS Toolkit for Visual Studio you can choose to deploy as a self contained deployment on the on the Application Options page of the wizard.

Self contained option in deployment wizard

Checking this option triggers the underlying call to dotnet publish to publish as a self contained application, and generate a Procfile for the deployment bundle to reflect the fact the application is self contained.

Conclusion

The new AWS Elastic Beanstalk support for .NET Core on Linux is one of the fastest ways to get your .NET Core web applications running in the cloud. You can focus on building your ASP.NET Core application and let Elastic Beanstalk handle the scaling, patching, and monitoring of your application. If you are already running a .NET Core application with the existing .NET on Windows Server platform migrating to the new platform can be as simple as creating a new environment with the new .NET Core on Linux platform. For more information checkout the Elastic Beanstalk developer guide here.

–Norm