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.
Also published on Medium.