Project Description
The project involves deploying a Flask app on AWS ECS Fargate and AWS ECR. Read More about the tech stack here
Task-01
Get a Flask application from GitHub.
Build the Dockerfile present in the repo
Setup AWS CLI and AWS Login to tag and push to ECR
Setup an ECS cluster
Create a Task Definition for the node js project with an ECR image
Run the Project and share it on LinkedIn :)
Happy Learning :)
ECS (Elastic Container Service)with Flask-app
Step 1: Creating an ECS Cluster
Navigate to ECS in the AWS console and click on Create cluster
Provide the name of the Cluster and attach the VPC & subnets.
This cluster will use the Cluster name as its default namespace.
We will be using AWS Fargate, as It is a serverless architecture that auto-scales our infra based on the requirement.
Leave the rest to defaults and click on Create
- Our ECS cluster is successfully created. Now we need to create an ECR Registry which is like a repo with Docker images and create a task under the task definitions and run it to deploy an application
(ECS Elastic Container Services) is like Docker, where we build our docker Image from the docker file and run the image to create a container.
ECR (Elastic container registry) is like a docker hub where we stored the newly created docker Images
Task definition is like the docker run command in (ECS Elastic Container Services)
Step 2: Creating Elastic Container registry
Navigate to Amazon ECR > Repositories > Create a repository
Choose the repo as private or public and give a it name.
- Select the content types and click on Create repository
- ECR repository is successfully created.
Step 3: Create an IAM USER and connect to the EC2 Instance. Build an Image and push it to ECR
Navigate to IAM and create an IAM user with proper policies to access ECS services.
Connect to the EC2 instance as the IAM user and Install docker as a prerequisite
Clone the repo from the GitHub using git clone command
git clone https://github.com/rjthapaa/flask-app-ecs.git
4. Navigate to ECR and open the repo that we created and click on view push commands
- Follow the steps as per the suggestion from the image and run it in the terminal
We have successfully created an IMAGE using a docker file and pushed it into the ECR repo
Now we have the Image, to run the image we need to create a task definition.
Step 3: Creating Task definitions
- Navigate to Task definitions > Create new task definition
Click on Create new task definition
Provide the container details and Image URI of the flask app from the ECR
Refer to the Image for image URI
Review and click on create
Our task definition is created, and now we need to deploy it.
Click on Deploy > Run task
Choose the Cluster that we want to use
Under Networking, check the security inbound rules and enable port 80
Skip the next and click on Create
The cluster will now provision our task from the task definition and deploy the Flask application
Open the task that is running inside the cluster and access the public
This is how we run our ECS Cluster with ECR and task definition,
Thank you for your time. Happy Learning
Try deploying Nodejs application using the same ECS and ECR
Git link