How to deploy ASP.NET WEB Application on Amazon Web Services(AWS)

In this article, we will learn how to deploy a Asp.Net WEB Application on Amazon Web Services(AWS) using AWS Toolkit with visual studio 17. You can also use earlier version of visual studio ( VS 15 or VS 13). If you are planning to learn how to deploy your application on AWS, You need to have AWS subscription. AWS provides 12 months free subscription with some limited features. This is something that attracts the novice learner. We can try AWS free for 12 months with usage per month terms & conditions but I personally think that the free usage is more than enough for personal website. Let’s start!

STEP 1 – Install AWS Toolkit for Visual Studio

AWS Toolkit for Visual Studio is an awesome plugin provided by Amazon for the Visual Studio IDE that makes it very easier for you to develop, debug, and deploy .NET applications that uses Amazon Web Services.

Note – The Toolkit for Visual Studio is supported for Visual Studio versions 2013 and later version.

The AWS Toolkit for Visual Studio conveniently includes the AWS SDK for .NET, so you can get started building .NET applications on AWS infrastructure services in Visual Studio, including Amazon S3, Amazon EC2, AWS Elastic Beanstalk, and Amazon DynamoDB.

Navigate the below link to download AWS Toolkit based on version of your VS IDE.

  • AWS Toolkit for Visual Studio 2017 – Download
  • AWS Toolkit for Visual Studio 2013-15 – Download
  • AWS Toolkit for Lower version of Visual Studio 2013 – Sorry 🙁

Once you download AWS Toolkit, you have to install it to integrate it with Visual Studio. Have a look at below pics.

Install – VSIX Installer


You can see installing aws toolkit for visual studio is modifying VS in order to make it integration with IDE.

To check whether it is installed in Visual Studio or not.

  • open visual studio
  • Go in View.
  • See AWS Explorer option are available or not.

If you see AWS Explorer that means AWS toolkit is successfully installed.

 

STEP 2 – Create an ASP.Net application either it is Web Forms, MVC or Web API.

Here, Just to make this article simple and to have focus only on how to deploy web application on AWS, I have already created MVC application(MVConAWS) with little bit changes. You can create your own application either it is Asp.Net web forms, MVC or WEB API.

STEP 3 – Create Group and User Profile on AWS

You need to have account profile in order to deploy application on AWS server. I hope you must have aws subscription if you are planning to deploy application on AWS.

To create a account profile, follow below steps

  • Open AWS dashboard
  • Select Services
  • Under Security, Identity &  Compliance category click on IAM.

ASP.NET WEB Application on Amazon Web Services

Now on IAM(Identity and Access Management) dashboard first we will be required to create a Group.

  • Click on Group name
  • Enter Group name
  • Click on Next Step

  • In next step, you will be asked to attach policy. Just leave as it is and click on Next Step.

  • Finally click on Create Group button


Ok now you have a group just click on group you have created. It will show there are no users in the group. So we will be required to create a user. Click on Users which is on left hand side menu. Then click on Create new users.

You can add multiple users at a time but I am just creating one. So just enter user name and click on create.

  • Enter user name
  • Select AWS access type
  • click on Next:Permissions button

  • Now add newly created User to existing group. Select Group
  • Click on Next button.

  • Here, you have to review your choices. After you create the user, you can view and download the autogenerated password and access key.
  • Click on Create User.


Now, User is successfully created and associated with existing group. You can view and download user security credentials. You can create new credentials at any time.  

Note down credentials(Access key ID and Secret access key), It would be required when you deploy application.

STEP 4 – Deploy on AWS

Now go back to visual studio and follow given steps

  • Open project.
  • Right click on project from solution explorer.
  • Click on Publish to AWS Elastic Beanstalk wizard.

On Publish to AWS Elastic Beanstalk window, Add account profile to use and select region and then click on Next button.

 

Now enter the URL. URL will be extended by AWS default URL .elasticbeanstalk.com like we get for Azure application.

You will notice that whatever unique URL you are entering is still showing error “Error during URL validation; check URL and try again”. It’s strange. I have spent much time on this part and finally got the solution. I have intentionally let this error come to make you understand why this is happening.

We are getting this error because of the missing settings while creating new user on AWS dashboard. We are getting the error because we have created a user but didn’t assign any permission or policies which are required for every user we will create. So keep that in mind!

So let’s fix it. Follow below steps to fix the issue.

  • Go to AWS dashboard
  • Select Services
  • Click on IAM (Under Security, Identity & Compliance)
  • Click on Users and click on the user you have created.

You have to grant permissions and attach policies. Click on Add permissions button under Permissions tab.

On Grant permissions page, Click on Attach existing policies directly button.

When you click on Attach existing policies directly button, you’ll see there are more than 300+ predefined policies are waiting to serve different purposes.

Policies are stored in AWS as JSON documents and specify the permissions that are allowed or denied for principals (identity-based policies) or resources (resource-based policies). IAM checks each policy that matches the context of the request. If a single policy includes a denied action, IAMdenies the entire request and stops evaluating policies.

We are done with AWS dashboard now go to Visual Studio screen where we had left and click on back and next again.

You will notice URL is showing valid now.

Here on AWS Options (Amazon EC2 Launch Configuration), you have to select appropriate configuration setting as per your need.

  • Select Container Type
  • Select Instance Type
  • Check Single instance environment
  • Click on Next button.

On this screen we are not doing anything for now. Just click next.

On this screen we are not doing anything for now. Just click next.

Click on Deploy button.

You are done. Now next everything will be done by AWS.

Once uploading completed 100%. Just wait 5-10 minute and  then navigate your application on any browser to check its working or not.

Step 5 – Test your application in browser.

When AWS complete uploading application deployment packages it will show all event with its status and show below result with link to our application.

If you are not able to see, Don’t worry! Click on AWS Explorer from View in menu bar. Expand AWS Elastic Beanstalk and click on your application name.

Now go to the http://mvconaws-test.us-west-2.elasticbeanstalk.com/ we had entered at the time configuration in order to deploy application on AWS.

Done… You’ve successfully published your application on AWS server.  As you can see AWS Toolkit made it so easy to configure and deploy application on AWS.

Further Reading :

https://aws.amazon.com/answers/web-applications/aws-web-app-deployment-dotnet/
https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_NET.quickstart.html
https://docs.aws.amazon.com/toolkit-for-visual-studio/latest/user-guide/deployment-beanstalk-traditional.html

I’ve tried to put almost all steps visually to make it easily understandable so you don’t miss or get confused while deploying application. In coming days we will learn something more exciting on AWS. Till then stay tuned!

HAPPY CODING 🙂

Share Knowledge
This entry was posted in ASP.NET, AWS and tagged , , , . Bookmark the permalink.

3 Responses to How to deploy ASP.NET WEB Application on Amazon Web Services(AWS)

  1. efrat says:

    hey, I flow you instructions and I’m still getting an error:

    Error executing the dotnet publish command, stopping deployment
    ..build of project archive failed, abandoning deployment

  2. Akash Goel says:

    Well explained and very helpful

Leave a Reply

Your email address will not be published. Required fields are marked *