Deploying a Web Application to AWS

Introduction 

 
n my previous article, I shared the basics of Amazon Web Services (AWS) and guided through the process of registering to AWS free tier. While working on how to deploy web applications to AWS, the first question comes to my mind is, “Wait, am I going to get billed for this"? The answer is No, if I stick to the "Free Tier" offerings. So don’t worry about the billing if you've chosen the free tier plan of AWS.
 

Getting ready

 
You will need the following to complete this tutorial: 
  • Introduction to AWS
  • Subscription of AWS
  • AWS Toolkit for Visual Studio – I will explain how to get and set this later in this tutorial.
  • Visual Studio – I will be using 2015. You can use any later versions as well.

Install AWS Toolkit for Visual Studio

 
Go to AWS toolkit for Visual Studio,
 
aws
 
Download the SDK and install it.
 
To check whether it is installed in Visual Studio or not, open Visual Studio – View.
 
If you see AWS Explorer in the View sub menu that means the AWS toolkit has been installed.
 
explorer
 

Creating a Project in Visual Studio 

 
Create a new MVC project.
 
Click on New Project > Web > ASP.NET Web Application.
 
new
 
Rename the application and click on OK.
 
On the next screen you have the choice to choose the web application type. I am choosing MVC with No Authentication.
 
Authentication
 
Choose your web application type and click on OK.
 
mvc
 
The application is ready now.
 
code
 
Do some editing if you want. I am a lazy guy so I am just leaving the application as it is and moving ahead to deployment part of the the application.
 
So, right-click on the project and click on Publish to AWS.
 
publish
 
On next screen is for publishing to AWS Elastic Beanstalk.
 
AWS Elastic Beanstalk
 
Currently there is no account profile so we have to create one first.
 
Creating Identity in AWS
 
Before deploying an application to AWS, you must have an identity. Identities are created using group and group policies. After a group is created, we can attached users to the group. In then end, AWS creates a pair of Access Key ID and Access Secret Key. This is the identity of the app that must be attached to the web application when we deploy it to AWS. 
 
For that first, go to AWS dashboard and under Security & Identity category click on IAM,
 
iam
 
Now on IAM dashboard, we need to create a Group and its policies. 
 
create
 
Give a proper name to the group.Usually, its a group that will have access to this application. For example, in your company, if the operations department should have access to this app, then that group needs to be a part of this group. 
 
group
 
Each group has some group policies. On the next screen, you're asked to attach a policy.
 
Don’t attach any policy to the group just click on Next Step.
 
next
 
And create a group.
 
create group
 
Ok now you have a group. Click on the group you just created. It will show that there are no users in the group. So we will be required to create a user. Click on Users, which is on the left-hand side menu. Then click on Create new users. If you already have users in your company account, you may see list of availalbe users. 
 
Create new users
 
You can add multiple users at a time but I am just creating one. So just enter the user name and click on Create.
 
create
 
What this Create button does it, it creates an identity for the app, which is required when we publish/deploy this app to AWS. 
 
Download the credentials and save them at an accessible location. 
 
See Download Credentials button below.  
 
Download
 
 
Finally, we have an Access Key ID and and Secret Access Key.
 
secret key
 
Now go back to the Visual Studio on Publish to AWS Elastic Beanstalk wizard and click on Add another account profile.
 
profile
 
A new screen will pop up to fill the profile credential. Fill all the details. 
  • Profile name – Give a app profile name. It can be anything.
  • Access Key ID and Secret Access Key - Enter what we had just created in the previous step.
  • Account number- optional.
  • Account Type - Default is selected. You will see more if you've multiple account types. 
Click OK once you've filled all the fields.
 
profile
 
Now we have a profile attached with this app that is going to be used deploy our application to AWS.
 
Now make sure the profile we have created is selected and Create a new application environment is selected. Click on next.
 
publish
 
On this screen, you have to select the environment or you can enter your own as per requirement. I am choosing a test as I am just testing this.
 
Now enter the URL. URL will be extended by AWS default URL .elasticbeanstalk.com. Your final public URL will be - YOURURL.elasticbeanstalk.com. This is similar to what we get for an Azure application.
 
You will notice that whatever unique URL you are entering, it will show an error, “Error during URL validation; check URL and try again”. It’s strange. I have spent so 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.
 
url
 
We are getting this error because of the missing settings while we created a new user on the AWS dashboard. So let’s fix it.
 
Go to the AWS dashboard – IAM – Users and click on the user you have created earlier.
 
dashboard
 
We are getting the error because we have created a user but didn’t assign any permissions or policies which are required for every user we will create. So keep that in mind!
 
Once you clicked on the user you have created it will take you to the user page like below.
 
attach
 
Click on Attach Policy.
 
We have to give full access to the user to AmazonEC2FullAccess & AWSElasticBeanstalkFullAccess.
 
access
 
attach
 
Once you select both the policies, click on Attach Policy.
 
atatch
 
Finally, we have access to policies we need for the user.
 
user
 
We are done with the AWS dashboard.
 
Now go back to Visual Studio screen where we had left and click on Back and Next buttons again.
 
You will notice URL is valid now.
 
url
 
 
Just click on Next now.
 
next
 
On this screen we are not doing anything for now. Just click Next.
 
On the next screen also we are not going to do anything as of now. Just click Next.
 
next
 
Again Click on Next.
 
next
 
Click on Finish and on the next screen just click Deploy.
 
deploy
 
You are done. Now next everything will be done by AWS.
 
It will take time to finish the deployment. Every event will be shown to you like below.
 
time
 
When AWS complete its work, it will show all event with its status and show below results with a link to our application.
 
application
 
That is the URL you can type or copy in your browser to access the application we had just deployed. 
 

Test the application
 

Go to the URL we had entered at the time of deployment.
 
It’s working!!
 
application
 
So finally, we have deployed an ASP.NET application to AWS. You can find your files uploaded on AWS on AWS dashboard – S3.
 
Click on S3 below and you will see your application files there. 
 
dashboard
 
dashboard
 
That’s all for this article. I tried to make it simpler and clearer to understand to every professional level – from beginners to expert – but still if you find any difficulty, please let me know. I will be happy to help.
 
In the next article, let's learn the process of Assign a Domain to an Application Deployed on AWS.
 
Keep learning!! Keep sharing!! Keep caring.
 
Read more articles on Visual Studio: