Project 6 - Day 85 Deploying an Flask application using ECS and ECR in AWS

Project 6 - Day 85 Deploying an Flask application using ECS and ECR in AWS

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

  1. Navigate to ECS in the AWS console and click on Create cluster

  2. Provide the name of the Cluster and attach the VPC & subnets.

    This cluster will use the Cluster name as its default namespace.

  1. We will be using AWS Fargate, as It is a serverless architecture that auto-scales our infra based on the requirement.

  2. Leave the rest to defaults and click on Create

  1. 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

  1. Navigate to Amazon ECR > Repositories > Create a repository

  2. Choose the repo as private or public and give a it name.

  1. Select the content types and click on Create repository

  1. 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

  1. Navigate to IAM and create an IAM user with proper policies to access ECS services.

  2. Connect to the EC2 instance as the IAM user and Install docker as a prerequisite

  3. 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

  1. 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

  1. Navigate to Task definitions > Create new task definition

  1. Click on Create new task definition

  2. 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