Part 2 - Deploy to Amazon EC2 with Elastic Beanstalk

Follow the steps below to deploy the ASP.NET Core Web API application to an Amazon EC2 instance running Windows Server Core.

1. Right-click your project in Solution Explorer, and select Publish to AWS Elastic Beanstalk to launch the publishing wizard. See the figure below.


2. Ensure the “Account profile to use” drop-down and “Region” drop-down are set to the profile and region you are using for today’s labs, and the deployment target is set to, “Create a new application environment”, and click Next

3. On the next step of the wizard, select a name for the application (or leave it set to the default), and then select a name for the environment. The pre-populated list will include environments ending in -dev, -test and -prod (or you can type your own).

4. AWS Elastic Beanstalk application environments are accessible via a public domain name (a subdomain of On the same step of the wizard, choose a subdomain for your Web API application, and check to ensure it’s available. Once you’ve confirmed a domain, click Next. See the figure below.


5. On the next step of the wizard, choose the application stack (called the “container type” in Elastic Beanstalk; it is not a Docker container, however). Choose the latest version of 64 bit Windows Server Core running IIS.

6. Choose an instance type, and ensure “single instance environment” is checked. Elastic Beanstalk can also deploy fully load-balanced applications, along with the load-balancer, but for this lab, you will deploy a single EC2 instance. For this application, the “t2.micro” instance type is sufficient.

7. If you don’t already have an EC2 key pair created (in the “Key pair” dropdown), select “<Create new key pair…>”, and enter a name for the key pair. When finished, click Next.

Note: The key pair is a cryptographic pair of keys, one public and one private. Windows EC2 Administrator login credentials are encrypted with the public key, which AWS stores, and can only be decrypted with the private key, which you keep. In this case, the AWS Toolkit for Visual Studio will store the private key for you.

8. On the next step of the wizard, you choose the permissions your application will inherit from the EC2 instance it’s running on by selecting the IAM Role that the EC2 instance itself will have. In the role dropdown, select check the box next to “CloudWatch Full Access” (under Role Templates) at the top of the drop-down list. This will create a new IAM role that has permissions to write to CloudWatch Logs. See the figure below.


9. The AWS Elastic Beanstalk service itself needs permissions in order to monitor and update your application environment. Select the role, “aws-elasticbeanstalk-service-role” from the Role dropdown under “Service Permissions”.

10. On the next step of the wizard, leave everything set to the defaults, with netcoreapp2.1 (or higher) showing as the framework version.

11. At the final step of the wizard, review your settings, and then click the Deploy button to begin deploying the app. After a few moments, the Elastic Beanstalk environment pane should automatically open in Visual Studio. If it doesn’t, find your new environment under the AWS Elastic Beanstalk node in the AWS Explorer pane of Visual Studio, and double-click it.

You can view the progress of the deployment in the Output Window. Once it has completed you are ready to move to the next part.