In this article, I will take you through how to deploy your first test .NET Core application to AWS EC2.
I wanted to try deploying my application to aws to for testing purposes. As it was known to me, ECS would be a good way to get started on serverless deployment. But afterward, I came to know that ECS is not a free service if you are deploying your application using AWS Free Tier.
Then chose to go with EC2 as it was just for testing purposes. You need to create an EC2 instance and start running your docker container inside it. Following are the details.
Create EC2 Linux Instance:
- Go to EC2 dashboard >> Instances >> Launch Instance
- Select the machine and version
- Select the instance type as t2.micro which is the lowest configuration type available
- Create new key-value pair and download the .pem file
- Then create the instance
Connect to EC2 through SSH:
- Go inside the instance
- Click on Connect button
- Go to the SSH option
- Copy highlighted command
- Open your terminal and go to the path where your download key-value pair .pem file is located
- Paste and run the copied command that will connect to the server
Install Docker on Instance:
- Visit https://docs.docker.com/engine/install/ubuntu/
- Apply commands mentioned in the above document to the connecter server.
- It will install the docker on your server.
- You can check the installed docker with the command >> docker –version
Upload Docker Image to ECR:
- Now build your app’s docker image on your local machine
- In AWS Console, go to Elastic Container Registry
- Create Private repository
- Login to aws through aws CLI and push your image to a registry
Pull Docker Image into the instance and Run:
- Now switch to the terminal where you are already connected to an EC2 instance
- Again login to the aws through aws commands and pull your image from the ECR registry
- Run the image using the docker run(with option) command
- Your app will get open when you visit the public IP
Note: If your app uses ports other than 80(default HTTP) and 443(default HTTPS) ports, create a new inbound rule to allow all traffic on the new port.