AWS Developer Tools Blog

AWS and .NET Core 2.0

Yesterday, .NET Core 2.0 was released, and at AWS we’re very excited about the new features and maturity added to the .NET Core platform. In the coming months, we’ll be updating AWS services to have first-class support for .NET Core 2.0. You can get started using .NET Core 2.0 on AWS right away in two easy ways.

Using AWS Elastic Beanstalk

Elastic Beanstalk lets you easily deploy web applications, and currently supports the .NET Framework and .NET Core 1.1. The Elastic Beanstalk platform will be updated to have .NET Core 2.0 soon. Until the platform is updated you can customize the deployment package to instruct Beanstalk to install .NET Core 2.0 on the instance during deployment.

When an ASP.NET Core application is deployed to Beanstalk a JSON manifest called aws-windows-deployment-manifest.json is created by the toolkit to instruct Beanstalk how to deploy the application. In a previous blog post we talked about how you can customize this manifest. We can use that ability to customize the manifest to run a PowerShell script before deployment to install .NET Core 2.0.

The first step is to add a file to our ASP.NET Core 2.0 project called aws-windows-deployment-manifest.json. In the properties window for aws-windows-deployment-manifest.json, be sure to set the Copy to Output Directory field to Copy Always. This file is normally generated by the toolkit but when the toolkit finds the file already exists it will instead modify the existing file with the settings made in the deployment wizard.

Next copy and paste the content below into the aws-windows-deployment-manifest.json. This says we want to deploy one ASP.NET Core application and before it is deployed execute the ./Scripts/installnetcore20.ps1 PowerShell script.


{
  "manifestVersion": 1,
  "deployments": {

    "aspNetCoreWeb": [
      {
        "name": "app",
        "parameters": {
          "appBundle": ".",
          "iisPath": "/",
          "iisWebSite": "Default Web Site"
        },
        "scripts": {
          "preInstall": {
            "file": "./Scripts/installnetcore20.ps1"
          }
        }
      }
    ]
  }
}

Now that we have added the manifest we need to add the PowerShell script. In the ASP.NET Core project add ./Scripts/installnetcore20.ps1 file. Again be sure to set the Copy to Output Directory field to Copy Always to make sure it is added to the deployment package. The script below downloads the .NET Core 2.0 installer and run the installer.

 


$localPath = 'C:\dotnet-sdk-2.0.0-win-x64.exe'

if(!(Test-Path $localPath))
{
    Invoke-WebRequest -Uri 'https://download.microsoft.com/download/0/F/D/0FD852A4-7EA1-4E2A-983A-0484AC19B92C/dotnet-sdk-2.0.0-win-x64.exe' -OutFile $localPath
    & $localPath /quiet /log c:\InstallNetCore20.log
}

In this script, I’m downloading .NET Core 2.0 from Microsoft’s official link. For a faster download during deployment and to protect yourself from the link being changed, I recommend copying the .NET Core 2.0 installation into an Amazon S3 bucket that is in the same region as your Elastic Beanstalk environment.

Now with this customization to the deployment manifest you can easily deploy ASP .NET Core 2.0 applications to Elastic Beanstalk today.

Using Docker-based services

For Docker-based services that execute Docker containers, such as Amazon EC2 Container Service and AWS CodeBuild, you can get started immediately by using the published Docker images from Docker Hub. For example, when setting up an AWS CodeBuild project in the console, you can specify a custom Docker image from Docker Hub.

For more information about the .NET Core Docker images, see the GitHub repository. For more information about running Docker containers on AWS, see Getting Started with Amazon ECS.

AWS SDK for .NET

.NET Core 2.0 supports .NET Standard 2.0 which means any NuGet packages that target .NET Standard 2.0 and below are supported on .NET Core 2.0. The AWS SDK for .NET targets .NET Standard 1.3 which means you can use it for either .NET Core 1.x or .NET Core 2.0.

Conclusion

To stay up to date about .NET Core 2.0 and AWS, keep following the AWS .NET Development blog and find us on Twitter.