This blog demonstrates deploying a simple application to Amazon ECS and Fargate. Amazon Elastic Container Service (ECS) is a fully managed container orchestration service that helps you to deploy, manage, and scale containerized applications more efficiently. This blog assumes that you have all the prerequisites in place.
- AWS Account.
- EC2 Instance with Docker and AWS CLI installed.
git clone https://github.com/pmgoriya/node-todo-cicd.git
The source code includes a Dockerfile. Build the docker images from the docker file by navigating to the source code directory and running the command below: sudo docker build -t todoapp .
Now, login to the AWS Management Console, go to Elastic Container Registry and create a public repository that will hold the docker image created in Step 2. Click Create Repository.
After creating the repository, follow the steps below to authenticate and push the docker image to the ECR repository that you just created. Get the commands from the ECR repository: Retrieve an authentication token and authenticate your Docker client to your registry. Use the AWS CLI:
sudo aws ecr-public get-login-password --region us-east-1 | sudo docker login --username AWS --password-stdin public.ecr.aws/r5h2p7m7
-
Tag your image so you can push the image to this repository: sudo docker tag todoapp:latest public.ecr.aws/r5h2p7m7/todoapp:latest
-
Run the following command to push this image to your newly created AWS repository: sudo docker push public.ecr.aws/r5h2p7m7/todo-app:latest
Our image has been pushed to Amazon Elastic Container Registry
Now we need to create the ECS Cluster where our service will reside. In the AWS Management Console, navigate to Elastic Container Service and create a Cluster select AWS Fargate (serverless) infrastructure. Provide the cluster name and select AWS Fargate, then click the Create button.
The cluster has been successfully created.
Under the Amazon ECS console, navigate to Task Definitions and click Create new task definition.
-
Under Infrastructure requirements, select AWS Fargate launch type, Linux/X86_64 Operating System architecture. For task size, select 1 vCPU and 2GB Memory. Select None for the task role and Create new role under the Task execution role section.
-
Specify a name, container image, and whether the container should be marked as essential. Each task definition must have at least one essential container. Add port mappings to allow the container to access ports on the host to send or receive traffic. Leave everything as default and click Create.
Under the Environment section, select an existing cluster that we created earlier and leave everything as default.
Under the Deployment configuration section, Specify what type of application you want to run provide the service name, and click Create.
The Service has been created and is up and running.