This content originally appeared on DEV Community and was authored by Pravesh Sudha
From Infrastructure as Code to CI/CD β How I Automated Deployment, Notifications & Cloud Setup
π‘ Introduction
Welcome to the world of DevOps! π Today, weβre diving into Flask by building a simple To-Do List application and then taking it to the next level with DevOps automation. This is part of our Python-for-DevOps series, where we combine Python development with real-world DevOps practices.
Iβve created a basic To-Do app in Flask using ChatGPT, and now, weβll supercharge it by integrating various DevOps tools:
β
AWS DynamoDB β To store our tasks efficiently in the cloud.
β
AWS SNS β To send an email notification whenever a task is marked as complete.
β
Docker β To containerize our application for easy deployment.
β
Terraform β To provision our AWS infrastructure as code.
β
Jenkins β To automate everything with a full CI/CD pipeline.
By the end of this tutorial, youβll have hands-on experience with key DevOps tools, and your Flask app will be fully automated, running smoothly in the cloud. Make sure to follow along till the end!
π‘Pre-Requisites
Before we dive into the project, letβs make sure we have everything we need. This tutorial assumes that you have:
β An AWS account β Weβll be using AWS services like DynamoDB and SNS, so make sure you have access. If you donβt have an acount, you can sign up for a free tier on AWS.
β Basic knowledge of Docker, Jenkins, and Terraform β You donβt need to be an expert, but a basic understanding of these tools will be helpful:
Docker β Weβll containerize our Flask app for easy deployment.
Jenkins β Weβll set up a CI/CD pipeline to automate deployment.
Terraform β Weβll use infrastructure as code to provision AWS resources.
If youβre new to any of these tools, donβt worry! Iβll guide you through the process step by step. Now that we have our prerequisites covered, letβs start by building our Flask To-Do app.
π‘ Setting Up the Host Machine (EC2 Instance) π
Before we start deploying our Flask To-Do app, we need a host machine where everything will run. For this, weβll create an AWS EC2 instance and set it up with all the necessary tools:
β
Docker β To containerize our Flask application.
β
Jenkins β To automate deployment with CI/CD.
β
Terraform β To provision AWS infrastructure.
β
AWS CLI β To interact with AWS services.
1οΈβ£ Launch an EC2 Instance
Head over to the AWS Management Console and create an EC2 instance with the following specifications:
Amazon Machine Image (AMI): Ubuntu (Latest LTS)
Instance Type:
t2.small
Storage: 15GB
Key Pair: Select an existing key or create a new one (download the
.pem
file).Security Group: Open ports 5000 (for Flask) and 8080 (for Jenkins).
Once the instance is up and running, connect to it using SSH:
ssh -i <your-key.pem> ubuntu@<your-instance-ip>
Now that weβre inside the EC2 instance, letβs install the required tools.
2οΈβ£ Install Docker
Docker will help us containerize our application so it runs smoothly across environments.
sudo apt update -y
sudo apt install -y docker.io
sudo systemctl enable --now docker
sudo usermod -aG docker $USER && newgrp docker
docker --version # Verify Docker installation
3οΈβ£ Install Java (Required for Jenkins)
Jenkins requires Java to run, so letβs install it:
sudo apt install -y fontconfig openjdk-17-jre
java -version # Verify Java installation
4οΈβ£ Install Jenkins (For CI/CD Automation)
Add the Jenkins repository and install Jenkins:
sudo wget -O /usr/share/keyrings/jenkins-keyring.asc https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
echo "deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] https://pkg.jenkins.io/debian-stable binary/" | sudo tee /etc/apt/sources.list.d/jenkins.list > /dev/null
sudo apt update -y
sudo apt install -y jenkins
sudo systemctl enable --now jenkins
Jenkins will now be running on port 8080.
5οΈβ£ Install Terraform (For Infrastructure as Code)
Terraform will help us automate AWS resource provisioning.
sudo apt update -y && sudo apt install -y gnupg software-properties-common
wget -O- https://apt.releases.hashicorp.com/gpg | gpg --dearmor | sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg > /dev/null
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
sudo apt update -y
sudo apt install -y terraform
terraform --version # Verify Terraform installation
6οΈβ£ Install AWS CLI (For AWS Interactions)
We need AWS CLI to communicate with AWS services like DynamoDB and SNS.
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
sudo apt install unzip -y
unzip awscliv2.zip
sudo ./aws/install
aws --version # Verify AWS CLI installation
# Add Jenkins to the docker group
sudo usermod -aG docker jenkins
7οΈβ£ Configure AWS Credentials
To allow Terraform and AWS CLI to access AWS services, configure your AWS credentials:
aws configure
This command will prompt you to enter:
AWS Access Key ID
AWS Secret Access Key
Default region β
us-east-1
Default output format β
json
π If you donβt have access keys, create them in AWS:
Go to AWS Console β IAM β Users
Select your user β Security Credentials
-
Click Create Access Key β Choose AWS CLI as the use case
-
Copy the Access Key ID and Secret Access Key
8οΈβ£ Open Required Ports in Security Group
Our application will run on port 5000 (Flask) and port 8080 (Jenkins). To ensure they are accessible, open these ports in the EC2 Security Group settings.
Now that our host machine is set up with all the necessary tools, weβre ready to deploy our Flask To-Do app.
π‘ Cloning the Project & Setting Up AWS Resources
Now that our host machine (EC2 instance) is ready, it's time to set up the Flask To-Do app and configure AWS resources like DynamoDB and SNS.
1οΈβ£ Clone the Project from GitHub
We'll start by cloning the Flask To-Do app from my GitHub repository:
git clone https://github.com/Pravesh-Sudha/Python-projects.git
This repository contains multiple projects, so navigate to the Flask To-Do app directory:
cd Python-projects/flask-todo-app
π Optional: Feel free to fork the repository and make some custom changes for a personal touch!
2οΈβ£ Configure the App (Environment Variables)
The config.py
file contains environment variables that you can modify:
SECRET_KEY = os.getenv("SECRET_KEY")
AWS_REGION = "us-east-1"
DYNAMODB_TABLE = "todo_tasks"
SNS_TOPIC_ARN = os.getenv("SNS_TOPIC_ARN")
EMAIL = "programmerpravesh@gmail.com" # Chang to Your Email
π Update these variables in config.py
, like setting your email for SNS notifications.
3οΈβ£ Create AWS DynamoDB Table & SNS Topic Using Terraform
Before testing the app, we need to create the DynamoDB table and SNS topic. Instead of manually creating them in AWS, we'll use Terraform to automate the setup.
Navigate to the Terraform setup directory inside the project:
cd terraform-setup
Before running Terraform, open main.tf
and update the SNS email endpoint (add your-email) to your own email.
Initialize Terraform
terraform init
This command downloads and sets up Terraform dependencies.
Apply Terraform Configuration
terraform apply --auto-approve
π This will create:
β
A DynamoDB table for storing to-do tasks.
β
An SNS topic for sending email notifications when a task is completed.
4οΈβ£ Configure SNS Subscription
Once Terraform finishes, you'll see the SNS Topic ARN in the output. Copy it and save it as an environment variable:
export SNS_TOPIC_ARN=<the-output-from-terraform>
Now, check your email inbox (the one you provided in
main.tf
). You should have received an email from AWS SNS. Click the confirmation link to activate your SNS subscription.
5οΈβ£ Install Python Dependencies & Run the Flask App
Now, navigate back to the Flask To-Do app directory:
cd ../flask-todo-app
π Set up a virtual environment & install dependencies:
sudo apt install python3.12-venv -y
python3 -m venv flask-env
source flask-env/bin/activate
pip3 install -r requirements.txt
π Run the Flask app on EC2 (publicly accessible)
flask run --host='0.0.0.0'
The application will now be running on:
http://<your-ec2-public-ip>:5000
π Congratulations! Your Flask To-Do App is live! π
If you go to your mails, you will have the notification of the completed tasks, in my Case, βVote for Trumpβ
Now that the app is running, weβll containerize it using Docker. Before that, use the following command to destroy the resources you create using terraform:
terraform destroy
π‘ Automating the Workflow with Jenkins π
Now that we have tested the Flask To-Do app manually, it's time to automate the entire process using Jenkins CI/CD. This will ensure that every time we push code changes, the application is built, tested, and deployed automatically.
1οΈβ£ Access Jenkins Dashboard
Jenkins runs on port 8080, so open your browser and go to:
http://<your-ec2-public-ip>:8080
Jenkins will ask for an admin password. Retrieve it using:
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
Copy the password, paste it into Jenkins, and continue.
β
Install suggested plugins
β
Skip "Create Admin User" (weβll use the default admin)
β
Jenkins is now ready!
2οΈβ£ Assign IAM Role to EC2 for AWS Access
Since our application interacts with DynamoDB and SNS, our EC2 instance needs permissions to access these AWS services.
Create IAM Role for EC2:
Go to AWS IAM Console β Roles
Click Create Role
Select AWS Service β EC2
Attach these policies:
* `AmazonDynamoDBFullAccess`
* `AmazonSNSFullAccess`
-
Name the role:
Flask-Todo-Dynamo-Role-For-EC2
Click Create Role
Attach Role to EC2 Instance:
Go to EC2 Dashboard β Instances
Select your Flask EC2 instance
Click Actions β Security β Modify IAM Role
Select
Flask-Todo-Dynamo-Role-For-EC2
and attach it
π Now, our EC2 instance can communicate with AWS services! β
3οΈβ£ Configure AWS Credentials in Jenkins
Jenkins needs AWS credentials to deploy infrastructure using Terraform. Letβs add them:
1οΈβ£ Go to Jenkins Dashboard β Manage Jenkins β Manage Credentials
2οΈβ£ Click System β Global Credentials
3οΈβ£ Click Add Credentials
4οΈβ£ Select Secret Text
5οΈβ£ Add two credentials:
AWS_ACCESS_KEY_ID (Your AWS Access Key)
AWS_SECRET_ACCESS_KEY (Your AWS Secret Key)
6οΈβ£ Click Save
β Jenkins now has AWS access!
4οΈβ£ Install Jenkins Plugins for AWS & Terraform
We need Jenkins plugins for Terraform and AWS authentication:
Go to Manage Jenkins β Manage Plugins
Search for and install:
β Terraform Plugin
β AWS Credentials PluginRestart Jenkins if required
β Jenkins is now ready to deploy AWS resources!
5οΈβ£ Set Up Jenkins Pipeline
Now, letβs create a Jenkins Pipeline to automate our deployment:
1οΈβ£ Go to Jenkins Dashboard β Click New Item
2οΈβ£ Enter a name:
Flask-Todo-Dynamo
3οΈβ£ Select Pipeline β Click OK
4οΈβ£ Scroll down to the Pipeline section
5οΈβ£ Set Pipeline from SCM
6οΈβ£ Select Git and enter the repository URL:
https://github.com/Pravesh-Sudha/python-projects
7οΈβ£ Change the branch from master
to main
8οΈβ£ Set the Script Path to:
flask-todo-app/Jenkinsfile
9οΈβ£ Click Save
β Jenkins is now set up to automate deployment!
6οΈβ£ Run the Pipeline π
Click Build Now
Jenkins will:
* Clone the repository
* Deploy the Flask app using Terraform
* Build and run the Docker container
* Start the Flask To-Do app
-
Once the pipeline is successful, open:
http://<your-ec2-public-ip>:5000
π Your Flask To-Do App is live! π
7οΈβ£ Final Step β Confirm SNS Subscription
Before testing email notifications, confirm the SNS subscription:
Go to your email inbox (the one set in
main.tf
)Look for an email from AWS SNS
Click the confirmation link
β Now, SNS will send an email whenever a task is completed!
π‘ Conclusion
Congratulations! π Youβve successfully built and automated a Flask To-Do App using AWS, Terraform, Docker, and Jenkins. Through this project, we explored the key concepts of DevOps and saw how different tools work together to create a fully automated CI/CD pipeline.
Key Takeaways:
β
Infrastructure as Code (IaC) β Used Terraform to automate AWS resource creation.
β
Containerization β Packaged the Flask app with Docker for easy deployment.
β
CI/CD Automation β Used Jenkins to automatically build, test, and deploy the app.
β
AWS Integration β Connected the app to DynamoDB for storage and SNS for email notifications.
This project provides a solid foundation for working with DevOps tools in real-world applications. You can extend it further by:
π Adding unit tests before deployment.
π Deploying the app on Kubernetes instead of a single EC2 instance.
π Implementing AWS Lambda for serverless task management.
Final Thoughts π‘
DevOps is all about automation, scalability, and efficiency. With this project, youβve taken a big step toward mastering these principles. Keep experimenting, improving, and applying these skills to bigger projects.
π¬ Have questions or feedback? Drop them in the comments!
π’ Found this useful? Share it with your fellow DevOps learners!
Happy Coding & Automating! ππ₯
β¨ For more informative blog, Follow me on Hashnode, X(Twitter) and LinkedIn.
This content originally appeared on DEV Community and was authored by Pravesh Sudha

Pravesh Sudha | Sciencx (2025-02-20T08:17:44+00:00) π Automating Flask To-Do App with AWS: Terraform, Jenkins & Docker. Retrieved from https://www.scien.cx/2025/02/20/%f0%9f%9a%80-automating-flask-to-do-app-with-aws-terraform-jenkins-docker/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.