Deploying an ASP.NET Core Application to Amazon Web Services

This is the second post in a series on deploying a very simple ASP.NET Core application to the major cloud provides. This post is going to be dealing with setup and deployment to Amazon Web Services (AWS).

The following is are the other posts in this series.

Google Cloud Platform
Amazon Web Services (this post)
Microsoft Azure

Sample Application

This is the same as the first post in the series, but am including it in case you missed that post. The sample application that we will be deploying is the basic Razor Pages applications created using the .NET CLI. The following commands are what I used to create the application, create a solution, and add the project to the solution. I ran all these commands in a CloudSample directory.

dotnet new razor
dotnet new sln
dotnet sln add CloudSample.csproj

Amazon Web Services

The rest of this post is going to be based on a couple of pieces of documentation from Amazon for the Visual Studio Toolkit and Beanstalk with .NET Core. I will be walking through the whole process but wanted to make sure you had access to the same information this post is based on.

AWS Toolkit for Visual Studio

Amazon provides a Visual Studio extension to aid in interactions with their platform from Visual Studio. To install open the Tools > Extensions and Updates menu. Select Online from the left side of the dialog and then search for AWS and select AWS Toolkit for Visual Studio 2017.

Click download, close Visual Studio to trigger installation, and restart Visual Studio after the extension’s installation has completed. When you open Visual Studio back up you should see the AWS Getting Started page with has this link to the IAM Users page in the AWS Console. This will land you on the following page where you have to either sign into your account or sign up for a new account.

After you get through the sign-up/in process you will be at the IAM console where we are going to add a new user by clicking the Add user button.

On the next page fill out the User name you want to use and check the Programmatic access check box and then click the Next: Permissions button.

The next page is all about what permissions the user will have which is handled via groups. Since my account doesn’t have any groups I need to create one using the Create group button.

On the Create group form enter the Group name you want to use. Next, use the search box for Policy type to find the policies related to Elastic Beanstalk. I have selected the full access policy for this sample, but if it is more than just a test this would require more research to see if that is the proper policy to use or not. When done click the Create group button.

This will return you to the group page from above. Click the Next: Review button to continue. The next page is just a review of the options selected on previous pages. Click the Create user button to continue.

The last page has a button to Download .csv, click it and download the file. Back over in Visual Studio on the AWS Getting Started page click the Import from csv file.

Browse and select the csv download above. Then click the Save and Close button on the AWS Getting Started page. After that is complete you should see the AWS Explorer window.

Sign up for AWS Elastic Beanstalk

If you notice in the AWS Explorer screenshot above the Please sign up for this service under AWS Elastic Beanstalk. Double click the Please sign up for this service it will open a new browser window. On this window click the Get started with AWS Elastic Beanstalk button.

The next page will prompt for payment information. After entering your information click the Secure Submit button. The next step is an automated phone call to verify that you who you say you are. The final step in signing up is to select your plan.

Select the Free plan to finish your sign up.

Publishing from Visual Studio

Now that sign up is complete hope back in Visual Studio and open the solution you want to publish. In the Solution Explorer window right-click on the project and click Publish to AWS Elastic Beanstalk.

This will open the Publish to Amazon Web Services dialog. I just took the defaults since this is a new application and I don’t have any existing enviroments. Click the Next button to continue.

On the next screen, an Application Name and Environment Name are needed. Fill them in and click Next.

The next screen is where you can configure the type and size of the EC2 instance that will back your application. I used the defaults. As always click Next when ready.

The next screen allows you to configure permissions. You will never guess, but I used the defaults and clicked Next.

The next screen allows you to pick your project build configuration and framework to use. The defaults are set based your project so they should be right. Click the Finish button.

The final screen is to review all the options. If you are happy with everything click the Deploy button.

During deployment, I saw the following error in my output window.

Caught AmazonIdentityManagementServiceException whilst setting up role: User:myUser/CloudSampleBlog is not authorized to perform: iam:GetInstanceProfile on resource: instance profile aws-elasticbeanstalk-ec2-role
Caught Exception whilst setting up service role: User: myUser/CloudSampleBlog is not authorized to perform: iam:PutRolePolicy on resource: role aws-elasticbeanstalk-service-role

This turned out to not really be an issue. I went to my Elastic Beanstalk Dashboard and the application was there and in the process of deploying. The whole process took around 5 minutes. Unlike with Google, I did have to find the URL in the dashboard instead of a browser being opened to the URL automatically.

Wrapping Up

Initial setup with AWS is much more complex than with Google. Redeployment was in the two-minute range which is much faster than what I saw with Google. Overall it seems that Elastic Beanstalk is on par with Google’s App Engine.

Don’t forget to shut down and/or delete your test project when you are finished to make sure you don’t get charged.

Deploying an ASP.NET Core Application to Amazon Web Services Read More »