Skip to content
Deploy Python flask with ECS Fargate
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
images
static
Dockerfile
README.md
app.py
index.html
requirements.txt

README.md

Learn to deploy Python Flask App using Docker, AWS ECS and AWS Fargate.

Deploy Python App using ECS Fargate

→ Use Docker to Deploy Flask App

  • Clone this project
  • Move to project directory
  • Run this to build the image:
docker build -t flask-demo-app .
  • Now we need to run the container from image. Run this command:
docker run -it -p 5000:5000 flask-demo-app:latest
  • You should be able to open the flask app in browser using:
http://localhost:5000

→ Use ECS Fargate to Deploy Flask App

  • Create Repository in Elastic Container Registry (ECR):

aws ecr create-repository --repository-name demo-flask-app

  • Get a command you can use for logging in to the ECR repository you’ve just created:

aws ecr get-login --region $YOUR_REGION --no-include-email

  • Let's put our local docker image to ECR (ACCOUNTID is your account id and REGIONNAME is your region):

docker tag flask-demo-app:latest ACCOUNTID.dkr.ecr.REGIONNAME.amazonaws.com

  • Go to ECS. Create cluster and click on get started

Create ECS Cluster

  • Write container name and give the link to the docker image and you uploaded in the preivous steps. You should be able to get it from ECR as well.

Enter ECR Image

  • Click on next

Task Definition

  • Make sure the service has ecsContainerRole Click on next

Service Definition

  • Click on next

Configure Definition

  • Finally, Review and create the cluster

Review Cluster

💯 Yay! You'll see the success message

You can’t perform that action at this time.