Set up ECS by setting up Nginx on ECS

Set up ECS by setting up Nginx on ECS

Elastic Container Service

Day 48 of #90DaysOfDevOps

What is ECS?

  • ECS (Elastic Container Service) is a fully managed container orchestration service provided by Amazon Web Services (AWS). It allows you to run and manage Docker containers on a cluster of virtual machines (EC2 instances) without having to manage the underlying infrastructure.

  • With ECS, you can easily deploy, manage, and scale your containerized applications using the AWS Management Console, the AWS CLI, or the API. ECS supports both "Fargate" and "EC2 launch types", which means you can run your containers on AWS-managed infrastructure or your own EC2 instances.

  • ECS also integrates with other AWS services, such as Elastic Load Balancing, Auto Scaling, and Amazon VPC, allowing you to build scalable and highly available applications. Additionally, ECS has support for Docker Compose and Kubernetes, making it easy to adopt existing container workflows.

  • Overall, ECS is a powerful and flexible container orchestration service that can help simplify the deployment and management of containerized applications in AWS.

Let's start.

To run nginx on ECS follow the below steps:

First, launch an EC2 instance and connect it through SSH.

Second, create an IAM user (refer to this link ๐Ÿ”— for creating IAM user) and give the following permissions:

If a user is already created, then just attach the permissions.

AmazonEC2FullAccess

AmazonECS_FullAccess

AmazonElasticContainerRegistryPublicFullAccess

Then, go back to your terminal (SSH EC2 instance)

Install Docker and AWS CLI and add Docker to the current user group.

Reboot the system.

sudo apt install docker.io awscli -y
sudo usermod -aG docker $USER
sudo reboot now

Next, configure AWS CLI and enter access key ID and secret access key of the IAM user (refer to this blog ๐Ÿ”— for generating access key ID and secret access key)

aws configure

After that, pull the nginx image from dockerHub.

docker pull nginx:latest

Now, to push the nginx image to a repository, first, create a repository on the Amazon Elastic Container Registry (AWS ECR)

second, start filling up the details given in the form such as

visibility settings: Public, repository name, select OS and architecture, then click on create.

Click on the repository from the dashboard and view push command:

Copy and paste commands one by one as given, however, I do not need to apply the second step because I already have the image and I do not need to build it. Moreover, as I have given the image name nginx:latest, the third step will be different than the given.

The image is successfully pushed to the registry.

Now, click on it and copy the URI.

Next, search and go to ECS (Elastic Container Service) and click on Get Started.

Then, create a cluster.

Enter a few details such as cluster name, select infrastructure as Fargete (serverless) and create.

Now, go to the Task definitions from the left side panel and click on Create.

Again here, fill up the details as required such as name, and select fargate as infrastructure.

Enter container details: name and URI, and enter the port number required for the application to run. Then click on Create.

Next, click on the task, then deploy and Run task.

Here, choose the cluster that we just created and leave other settings as it is.

Now, you can find the task in the cluster section at the bottom, click on it.

Scroll down, copy the IP and paste it into the browser. The Nginx would be working.

Thank You.

ย