Skip to main content

Command Palette

Search for a command to run...

πŸš€ AWS CI/CD Pipeline | End-to-End Deployment Using CodePipeline & CodeDeploy

Build an automated deployment pipeline for a Dockerized Python Flask application using GitHub, AWS CodePipeline, AWS CodeDeploy, and EC2.

Updated
β€’24 min readβ€’View as Markdown
πŸš€ AWS CI/CD Pipeline | End-to-End Deployment Using CodePipeline & CodeDeploy
H
πŸ‘‹ Hi, I’m Hritik Ranjan β€” a B.Tech CSE student and a passionate tech enthusiast focused on Quality Engineering, AI/ML, Cybersecurity, and DevOps. πŸ’‘ I enjoy building and testing scalable, secure, and intelligent systems that solve real-world problems. My expertise and interests include: πŸ”Ή Quality Assurance & Testing Hands-on experience in manual and automation testing using Selenium & Java, ensuring high-quality and reliable applications. πŸ”Ή Artificial Intelligence & Machine Learning Exploring advanced algorithms and developing intelligent systems for practical use cases. πŸ”Ή Cybersecurity Focused on vulnerability assessment, security testing, and system hardening. πŸ”Ή Web Development Building responsive and user-friendly applications using modern technologies. πŸ”Ή Data Science Analyzing complex data to extract actionable insights. πŸ’Ό Key Projects: πŸš€ Blindness Detection System Applied computer vision techniques to detect blindness-related conditions. πŸš€ AI-Powered Rail Madad Enhancement Developed an intelligent complaint management system to improve railway customer service. πŸš€ Interactive Applications Built multiple projects like quiz apps, calculators, and productivity tools. 🌱 I’m continuously learning and improving my skills in DevOps, Cloud, and Automation to become a well-rounded engineer. 🀝 Open to collaborations, internships, and opportunities in QA, DevOps, AI/ML, and Cybersecurity. πŸ“« Let’s connect: hritikranjan1408@gmail.com

In this project, we will build an end-to-end CI/CD pipeline on AWS that automatically deploys a Python Flask application to an EC2 instance.

The project focuses mainly on the Continuous Delivery (CD) part of the pipeline using AWS CodeDeploy and then integrates CodeDeploy with AWS CodePipeline.

By the end of this project, the workflow will look like:

Developer
   β”‚
   β”‚ git push
   β–Ό
GitHub Repository
   β”‚
   β–Ό
AWS CodePipeline
   β”‚
   β–Ό
Source Stage
   β”‚
   β–Ό
Build / CI Stage
   β”‚
   β–Ό
AWS CodeDeploy
   β”‚
   β–Ό
EC2 Instance
   β”‚
   β”œβ”€β”€ CodeDeploy Agent
   β”œβ”€β”€ Docker
   └── Flask Application

πŸ“š Table of Contents


🎯 What We Are Building

Our goal is to deploy a Python Flask application running inside a Docker container onto an AWS EC2 instance.

Instead of manually connecting to the EC2 server every time we release a new version, we want AWS to automatically deploy the latest version.

The final workflow will be:

Developer pushes code
        ↓
GitHub
        ↓
CodePipeline
        ↓
CodeDeploy
        ↓
EC2
        ↓
Docker Container
        ↓
Flask Application

This means whenever new code is pushed into the configured repository, the pipeline can automatically take that code through the required stages and deploy it to the EC2 server.


πŸ€” What is CI/CD?

CI/CD stands for:

  • CI β†’ Continuous Integration

  • CD β†’ Continuous Delivery / Continuous Deployment

CI/CD is a software development approach that automates the process of:

Code β†’ Build β†’ Test β†’ Package β†’ Deploy

Without CI/CD, developers may have to manually build applications, copy files to servers, restart applications, and verify deployments.

With CI/CD, these activities can be automated.


πŸ”„ CI vs CD

Continuous Integration β€” CI

Continuous Integration focuses on automatically validating new code changes.

For example:

Developer
   ↓
Git Push
   ↓
Build
   ↓
Unit Tests
   ↓
Package

The objective is to identify problems early.


Continuous Delivery β€” CD

Continuous Delivery focuses on taking successfully built application code and deploying it to an environment.

For example:

Build Artifact
     ↓
CodeDeploy
     ↓
EC2
     ↓
Application

In this project, AWS CodeDeploy is responsible for the deployment process.


☁️ AWS Services Used

We will use the following components:

Service Purpose
GitHub Source code repository
AWS CodePipeline Orchestrates the pipeline
AWS CodeDeploy Automates deployment
Amazon EC2 Deployment server
IAM Permissions and access control
Docker Runs the application container
Python Flask Sample application

πŸ—οΈ Project Architecture

The high-level architecture looks like this:

                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚     Developer    β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                             β”‚
                          git push
                             β”‚
                             β–Ό
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚      GitHub      β”‚
                    β”‚   Source Code    β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                             β”‚
                             β–Ό
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚  CodePipeline    β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                             β”‚
                             β–Ό
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚   CodeDeploy     β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                             β”‚
                             β–Ό
              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
              β”‚          EC2 Instance        β”‚
              β”‚                              β”‚
              β”‚   CodeDeploy Agent           β”‚
              β”‚   Docker                     β”‚
              β”‚                              β”‚
              β”‚       Docker Container       β”‚
              β”‚              β”‚               β”‚
              β”‚              β–Ό               β”‚
              β”‚       Python Flask App       β”‚
              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

🧰 Prerequisites

Before starting this project, you should have basic knowledge of:

  • AWS

  • EC2

  • IAM

  • Git/GitHub

  • Linux

  • Docker

  • Basic Python

  • Basic CI/CD concepts

You should also have:

  • An AWS account

  • A GitHub repository

  • A sample Flask application

  • An EC2 instance

  • Permission to create IAM roles and AWS services


πŸ“ Step 1: Prepare the Application

First, we need an application that will be deployed.

For this project, we are using a Python Flask application.

A simple project structure can look like:

project/
β”‚
β”œβ”€β”€ app.py
β”œβ”€β”€ Dockerfile
β”œβ”€β”€ appspec.yml
β”œβ”€β”€ start_container.sh
β”œβ”€β”€ stopcontainer.sh
└── requirements.txt

Let's understand these files.

app.py

This contains our Flask application.

Example:

from flask import Flask

app = Flask(__name__)

@app.route("/")
def home():
    return "Hello from AWS CI/CD Pipeline!"

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=5000)

The application listens on port 5000 inside the container.


🐳 Dockerfile

We use Docker to package our application and its dependencies.

Example:

FROM python:3.10

WORKDIR /app

COPY requirements.txt .

RUN pip install -r requirements.txt

COPY . .

EXPOSE 5000

CMD ["python", "app.py"]

The Dockerfile tells Docker how to create the application image.


πŸ“¦ requirements.txt

This file contains the Python dependencies.

For example:

Flask

πŸ“œ Step 2: Understand appspec.yml

One of the most important files in AWS CodeDeploy is:

appspec.yml

The appspec.yml file tells CodeDeploy how the application should be deployed.

It defines deployment instructions and lifecycle hooks.

A simplified example can look like:

version: 0.0

os: linux

files:
  - source: /
    destination: /home/ubuntu/app

hooks:
  ApplicationStop:
    - location: stopcontainer.sh
      timeout: 300
      runas: root

  ApplicationStart:
    - location: start_container.sh
      timeout: 300
      runas: root

The exact configuration can vary depending on the application and deployment design.


πŸ”„ CodeDeploy Lifecycle

CodeDeploy provides lifecycle events that allow us to execute scripts during deployment.

For example:

ApplicationStop
      ↓
Download / Install Files
      ↓
ApplicationStart
      ↓
Application Running

This is useful because we can automatically:

  • Stop the old container

  • Copy the new application files

  • Build/start the new container

  • Start the updated application


πŸ›‘ stopcontainer.sh

The purpose of this script is to stop the currently running application container before deploying the new version.

Example:

#!/bin/bash

docker stop flask-app || true
docker rm flask-app || true

The || true prevents the deployment from failing if the container does not already exist.


▢️ start_container.sh

This script starts the new application.

For example:

#!/bin/bash

cd /home/ubuntu/app

docker build -t flask-app .

docker run -d \
  --name flask-app \
  -p 80:5000 \
  flask-app

Now the application running on container port 5000 is exposed through EC2 port 80.


πŸ–₯️ Step 3: Create the EC2 Instance

Now we need an EC2 instance that will act as our deployment target.

From the AWS Console:

AWS Console
    ↓
EC2
    ↓
Launch Instance

Select an Ubuntu AMI.

For learning purposes, choose an appropriate small instance type that fits your AWS account and budget.


πŸ” Configure Security Group

We need to allow the traffic required to access our server.

Typical rules could include:

Protocol Port Purpose
SSH 22 Remote administration
HTTP 80 Application access

For SSH, restrict the source to your own IP whenever possible.

Avoid opening administrative ports such as SSH to the entire internet unless there is a specific reason.


πŸ”‘ Connect to EC2

After launching the instance, connect using SSH.

Example:

ssh -i my-key.pem ubuntu@<EC2_PUBLIC_IP>

Make sure the private key has appropriate permissions:

chmod 600 my-key.pem

🐳 Step 4: Install Docker

Our application will run inside a Docker container, so Docker must be available on the EC2 instance.

First update the system:

sudo apt update

Then install Docker:

sudo apt install docker.io -y

Check the installation:

docker --version

Also verify that Docker is running:

sudo systemctl status docker

πŸ€– Step 5: Install CodeDeploy Agent

The CodeDeploy Agent is a software component installed on the deployment target.

It allows AWS CodeDeploy to communicate with the EC2 instance and execute deployment instructions.

The basic flow is:

AWS CodeDeploy
       ↓
CodeDeploy Agent
       ↓
EC2 Instance
       ↓
Application Deployment

The agent must be installed and running on the target EC2 instance.

After installation, verify its status using the appropriate service command for your system.

For example:

sudo systemctl status codedeploy-agent

If the service is running, the EC2 instance can communicate with CodeDeploy.


πŸ” Step 6: Create IAM Role

IAM is extremely important in AWS CI/CD.

AWS services need permission to interact with other AWS resources.

For example:

CodeDeploy
    ↓
Needs permission
    ↓
EC2

An IAM role can provide the required permissions.


πŸ‘€ EC2 IAM Role

The EC2 instance should have an IAM role that provides the permissions required by the CodeDeploy agent and application.

When configuring the role, follow the principle of least privilege.

That means:

Give only the permissions that are actually required.

Avoid giving broad administrator permissions unnecessarily.


πŸš€ Step 7: Create CodeDeploy Application

Now let's create an AWS CodeDeploy application.

Go to:

AWS Console
     ↓
CodeDeploy
     ↓
Applications
     ↓
Create application

Choose:

Compute Platform: EC2/On-premises

Give the application a meaningful name.

For example:

flask-cicd-app

πŸ‘₯ Step 8: Create Deployment Group

After creating the CodeDeploy application, create a Deployment Group.

The deployment group tells CodeDeploy:

"Which EC2 instances should receive this deployment?"

We can identify instances using tags.

For example:

Key: Environment
Value: Production

Then CodeDeploy can deploy to EC2 instances matching that tag.


🏷️ Why Use EC2 Tags?

Tags help AWS identify and organize resources.

For example:

Environment = Production
Application = Flask
Team = DevOps

CodeDeploy can use these tags to select deployment targets.


πŸ“¦ Step 9: Create Deployment

Now our application repository should contain the required deployment files:

app.py
Dockerfile
requirements.txt
appspec.yml
start_container.sh
stopcontainer.sh

The source package is provided to CodeDeploy.

CodeDeploy reads:

appspec.yml

and follows the deployment instructions.


πŸ”„ Deployment Flow

The deployment process looks like:

Source Package
      ↓
CodeDeploy
      ↓
ApplicationStop
      ↓
Files Copied
      ↓
ApplicationStart
      ↓
Docker Image Built
      ↓
Docker Container Started
      ↓
Application Available

πŸ”— Step 10: Integrate CodeDeploy with CodePipeline

Now we connect CodeDeploy with AWS CodePipeline.

This is where our project becomes an end-to-end automated pipeline.

The pipeline can be represented as:

GitHub
   ↓
CodePipeline
   ↓
Source
   ↓
Build / CI
   ↓
CodeDeploy
   ↓
EC2
   ↓
Docker
   ↓
Flask Application

CodePipeline acts as the orchestrator.

It coordinates the different stages of the software delivery process.


πŸ—οΈ Create the CodePipeline

Go to:

AWS Console
      ↓
CodePipeline
      ↓
Create Pipeline

Give the pipeline a meaningful name.

Example:

flask-cicd-pipeline

πŸ“₯ Source Stage

Configure GitHub as the source provider.

The pipeline will retrieve the latest application code from the configured repository.

Whenever the source changes according to the configured trigger, the pipeline can start a new execution.


πŸ”¨ Build Stage

If your project already has a CI/build stage, CodePipeline can pass the resulting application package to the deployment stage.

The important idea is:

Source
   ↓
Build
   ↓
Deployment

Only after the required previous stage succeeds should the deployment stage proceed.


πŸš€ Deployment Stage

For the deployment stage, select:

Provider:
AWS CodeDeploy

Then select:

Application
Deployment Group

that you created earlier.

Now CodePipeline knows where to send the application.


🎯 Complete Pipeline

Our final pipeline looks like:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚    GitHub    β”‚
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
       β”‚
       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ CodePipeline β”‚
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
       β”‚
       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚    Source    β”‚
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
       β”‚
       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚     Build    β”‚
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
       β”‚
       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  CodeDeploy  β”‚
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
       β”‚
       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚     EC2 Instance    β”‚
β”‚                     β”‚
β”‚  CodeDeploy Agent   β”‚
β”‚        ↓            β”‚
β”‚      Docker         β”‚
β”‚        ↓            β”‚
β”‚  Flask Container    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ§ͺ Step 11: Test the Complete Pipeline

Now let's test the pipeline.

Make a small change to your application.

For example:

return "Hello from AWS CI/CD Pipeline - Version 2!"

Commit the change:

git add .
git commit -m "Update application"
git push

The pipeline should detect the new source version according to its configured trigger.

Then:

GitHub
   ↓
CodePipeline
   ↓
CodeDeploy
   ↓
EC2
   ↓
Docker
   ↓
New Application Version

🌐 Verify the Application

Once deployment succeeds, access the EC2 instance using the configured application endpoint.

If the application is exposed on port 80, you can access:

http://<EC2_PUBLIC_IP>

If everything is configured correctly, the updated Flask application should be displayed.


πŸ” How Does CodeDeploy Know What to Do?

This is one of the most important beginner questions.

CodeDeploy uses:

appspec.yml

The file defines:

  • Which files should be deployed

  • Where they should be copied

  • Which lifecycle scripts should run

  • When those scripts should run

For example:

ApplicationStop
       ↓
Stop old application
       ↓
Deploy files
       ↓
ApplicationStart
       ↓
Start new application

πŸ› οΈ Common Problems & Troubleshooting

During real deployments, things don't always work on the first attempt.

Here are some common problems highlighted by this project.


❌ 1. CodeDeploy Agent Not Running

Check:

sudo systemctl status codedeploy-agent

If it is stopped, start it using the appropriate system service command.

The CodeDeploy agent must be healthy for deployments to work.


❌ 2. Docker Is Not Installed

If your deployment script executes:

docker build

but Docker is not installed, the deployment will fail.

Check:

docker --version

Install Docker if necessary.


❌ 3. Docker Permission Issues

The deployment user may not have permission to communicate with Docker.

Check Docker permissions and ensure the deployment scripts execute with the appropriate user privileges.


❌ 4. Port Already in Use

Suppose your container uses:

-p 80:5000

but another process is already using port 80.

The new container may fail to start.

Check listening ports:

sudo ss -tulpn

You can then identify which process is using the required port.


❌ 5. Old Container Is Still Running

If the previous container is still running, the new container may fail because of:

Container name conflict

or:

Port already allocated

That's why the stop script is important.

Example:

docker stop flask-app || true
docker rm flask-app || true

❌ 6. Incorrect appspec.yml

A small mistake in:

appspec.yml

can cause deployment failure.

Check:

  • File name

  • YAML indentation

  • Script paths

  • Destination directories

  • Lifecycle hook names

  • File permissions


❌ 7. IAM Permission Problems

AWS services need appropriate permissions.

If the required IAM role does not have sufficient permissions, deployment operations can fail.

Always check:

IAM Role
   ↓
Required Permissions
   ↓
AWS Service Access

πŸ“‚ Important Project Files

A useful project structure is:

flask-cicd-project/
β”‚
β”œβ”€β”€ app.py
β”‚
β”œβ”€β”€ requirements.txt
β”‚
β”œβ”€β”€ Dockerfile
β”‚
β”œβ”€β”€ appspec.yml
β”‚
β”œβ”€β”€ start_container.sh
β”‚
└── stopcontainer.sh

Each file has a specific responsibility.

File Purpose
app.py Flask application
requirements.txt Python dependencies
Dockerfile Creates Docker image
appspec.yml CodeDeploy deployment instructions
start_container.sh Starts new container
stopcontainer.sh Stops old container

🧠 Key Concepts

1. AWS CodeDeploy

CodeDeploy automates application deployments to supported compute environments such as EC2.

It removes much of the manual work involved in copying application files and executing deployment scripts.


2. CodeDeploy Agent

The CodeDeploy Agent runs on the deployment target.

It communicates with AWS CodeDeploy and executes the deployment instructions.


3. appspec.yml

This is the deployment configuration file.

It defines:

Files
Hooks
Lifecycle Events
Deployment Instructions

4. Lifecycle Hooks

Lifecycle hooks allow scripts to execute at specific stages of deployment.

Examples include:

ApplicationStop
ApplicationStart

5. CodePipeline

CodePipeline orchestrates the different stages of the CI/CD workflow.

For example:

Source
  ↓
Build
  ↓
Deploy

6. IAM Role

IAM roles provide AWS resources and services with the permissions they need.

They are preferable to embedding long-term AWS credentials inside application code or deployment scripts.


7. EC2

Amazon EC2 provides the virtual server where our application is ultimately deployed.


8. Docker

Docker packages the Flask application and its dependencies into a container.

This makes the application environment more consistent.


πŸ”₯ Why Use Docker in This Project?

Without Docker, we might need to manually configure:

Python
Flask
Dependencies
System Libraries
Application Configuration

With Docker, we package the environment into an image.

Dockerfile
    ↓
Docker Image
    ↓
Docker Container
    ↓
Flask Application

This provides a more consistent deployment process.


πŸ”„ Manual Deployment vs CI/CD Deployment

❌ Traditional Manual Deployment

Developer
    ↓
SSH into EC2
    ↓
Pull latest code
    ↓
Install dependencies
    ↓
Stop application
    ↓
Start application
    ↓
Verify

This process is repetitive and error-prone.

βœ… Automated Deployment

Developer
    ↓
Git Push
    ↓
CodePipeline
    ↓
CodeDeploy
    ↓
EC2
    ↓
Docker
    ↓
Application

This is faster, repeatable, and easier to standardize.


🎯 What I Learned From This Project

This project helped me understand how different AWS services work together to create a practical CI/CD pipeline.

The major concepts covered were:

  • AWS CodePipeline

  • AWS CodeDeploy

  • EC2

  • IAM Roles

  • CodeDeploy Agent

  • Docker

  • Flask

  • appspec.yml

  • Deployment lifecycle hooks

  • Shell scripts

  • Automated deployments

  • CI/CD workflow

  • Deployment troubleshooting


πŸ’‘ Important Interview Questions

Q1. What is AWS CodeDeploy?

Answer:

AWS CodeDeploy is an AWS deployment service that automates application deployments to supported compute environments such as EC2.

It helps automate tasks such as transferring application files, executing deployment scripts, and managing application lifecycle events.


Q2. What is the CodeDeploy Agent?

Answer:

The CodeDeploy Agent is software installed on the deployment target, such as an EC2 instance.

It communicates with CodeDeploy and executes the deployment instructions provided by the deployment package.


Q3. What is appspec.yml?

Answer:

appspec.yml is a configuration file used by AWS CodeDeploy to define deployment instructions.

It can specify files to copy and lifecycle hooks that execute scripts during deployment.


Q4. Why do we need an IAM role?

Answer:

An IAM role provides the required permissions to AWS services and resources without embedding long-term credentials directly into the application.

For example, an EC2 instance can use an IAM role to access AWS services securely.


Q5. What is the difference between CodePipeline and CodeDeploy?

Answer:

CodePipeline is used to orchestrate the complete CI/CD workflow.

CodeDeploy is focused specifically on application deployment.

For example:

CodePipeline
    ↓
Orchestrates pipeline
    ↓
CodeDeploy
    ↓
Deploys application to EC2

Q6. Why are deployment scripts used?

Answer:

Deployment scripts automate repetitive deployment tasks.

In this project:

stopcontainer.sh

stops the previous container, while:

start_container.sh

starts the new application container.


Q7. Why use Docker?

Answer:

Docker packages the application and its dependencies into a portable container.

This helps create a consistent application environment between development and deployment.


Q8. What happens when a developer pushes new code?

Answer:

In our configured pipeline, a new source change can trigger CodePipeline.

The pipeline retrieves the updated code, processes the configured stages, and then invokes CodeDeploy to deploy the new version to the EC2 instance.


Q9. What happens if the deployment fails?

Answer:

We should check the deployment status and logs, then verify:

  • CodeDeploy Agent

  • IAM permissions

  • appspec.yml

  • Deployment scripts

  • Docker installation

  • Docker container status

  • Port availability

  • EC2 configuration


Q10. What is the purpose of ApplicationStop?

Answer:

ApplicationStop is a CodeDeploy lifecycle event that can be used to execute commands before the new application version is deployed.

In this project, it can be used to stop the existing Docker container.


πŸš€ Final Architecture

After completing this project, our application delivery architecture looks like:

                         DEVELOPER
                             β”‚
                             β”‚ git push
                             β–Ό
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚     GitHub      β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                             β”‚
                             β–Ό
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚  CodePipeline   β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                             β”‚
                       Source / Build
                             β”‚
                             β–Ό
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚   CodeDeploy    β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                             β”‚
                             β–Ό
              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
              β”‚          EC2 Server         β”‚
              β”‚                             β”‚
              β”‚   CodeDeploy Agent          β”‚
              β”‚          β”‚                  β”‚
              β”‚          β–Ό                  β”‚
              β”‚        Docker               β”‚
              β”‚          β”‚                  β”‚
              β”‚          β–Ό                  β”‚
              β”‚   Flask Container           β”‚
              β”‚          β”‚                  β”‚
              β”‚          β–Ό                  β”‚
              β”‚    Flask Application        β”‚
              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“ Key Takeaways

The most important thing to understand from this project is not just how to click through the AWS Console.

The important concept is understanding how the services communicate with each other.

GitHub
  ↓
CodePipeline
  ↓
CodeDeploy
  ↓
CodeDeploy Agent
  ↓
EC2
  ↓
Docker
  ↓
Flask Application

Each component has a specific responsibility.

  • GitHub β†’ Stores source code

  • CodePipeline β†’ Orchestrates the delivery workflow

  • CodeDeploy β†’ Handles application deployment

  • CodeDeploy Agent β†’ Communicates with the EC2 target

  • EC2 β†’ Provides the server

  • Docker β†’ Runs the application container

  • Flask β†’ Provides the application


🏁 Conclusion

In this project, we implemented a practical AWS CI/CD deployment workflow using CodePipeline, CodeDeploy, EC2, IAM, Docker, and GitHub.

We started with a Python Flask application and prepared it for automated deployment using:

Dockerfile
appspec.yml
start_container.sh
stopcontainer.sh

We then configured an EC2 deployment target, installed the CodeDeploy Agent, configured IAM permissions, created a CodeDeploy application and deployment group, and finally integrated CodeDeploy with CodePipeline.

The final result is an automated deployment workflow:

Code Change
     ↓
GitHub
     ↓
CodePipeline
     ↓
CodeDeploy
     ↓
EC2
     ↓
Docker
     ↓
Updated Flask Application

This project provides a strong foundation for understanding how AWS-managed services can be combined to build a practical CI/CD workflow.

πŸš€ The real DevOps mindset is not just knowing individual tools β€” it is understanding how to connect those tools to build an automated, reliable, and repeatable software delivery process.


πŸ”— Reference

πŸ“Ί AWS Ultimate CI/CD Pipeline | End-to-End Demo | AWS CodePipeline

https://youtu.be/8ftrKNbSv28?si=d0sHbYjlPyFtsQBT



πŸš€ Continue Your Learning Journey

Thank you for taking the time to read this article.

Technology is evolving rapidly, and continuous learning is one of the most valuable investments you can make in your career. Whether you're exploring DevOps, Cloud Computing, Artificial Intelligence, Cybersecurity, Software Development, Data Science, or Career Growth, the resources below can help you deepen your knowledge and stay ahead in the industry.


πŸŽ“ Recommended Learning Platforms

πŸš€ Coursera

Learn from world-renowned universities and industry leaders including Google, IBM, Stanford, Microsoft, Meta, and many more.

βœ” Professional Certificates βœ” Career-focused Learning Paths βœ” AI & Machine Learning Programs βœ” Cloud & DevOps Certifications βœ” Business & Leadership Courses

πŸ”— https://imp.i384100.net/k0KvbV


πŸ’» Udemy

One of the largest online learning platforms with practical, hands-on courses covering:

βœ” DevOps & Kubernetes βœ” Docker & Cloud Computing βœ” AWS, Azure & GCP βœ” Programming & Development βœ” Cybersecurity & Ethical Hacking

πŸ”— https://trk.udemy.com/MAL2MY


πŸ“Š DataCamp

A great platform for anyone interested in:

βœ” Python Programming βœ” SQL & Databases βœ” Data Analytics βœ” Machine Learning βœ” Artificial Intelligence

Interactive learning paths and hands-on projects make it ideal for beginners and professionals alike.

πŸ”— https://datacamp.pxf.io/nX4kER


πŸŽ“ edX

Access high-quality courses and certifications from leading institutions such as:

βœ” Harvard University βœ” MIT βœ” Berkeley βœ” Microsoft

Perfect for learners seeking university-level education online.

πŸ”— https://edx.sjv.io/POvVeN


🎨 Domestika

Enhance your creative skills with courses on:

βœ” Graphic Design βœ” Video Editing βœ” Animation βœ” Digital Marketing βœ” Content Creation

πŸ”— https://domestika.sjv.io/dynKAW


πŸ› οΈ Recommended Tools & Resources

πŸ”₯ AppSumo

Discover exclusive lifetime deals on:

βœ” AI Tools βœ” Productivity Software βœ” Developer Utilities βœ” Marketing Platforms βœ” Business Applications

A must-have resource for developers, creators, freelancers, and entrepreneurs looking to save money while accessing premium tools.

πŸ”— https://appsumo.8odi.net/L04a33


πŸ›’ Shopify

Looking to start an online business or launch an eCommerce store?

Shopify provides everything you need to build, manage, and scale an online business.

βœ” Online Store Builder βœ” Payment Integration βœ” Inventory Management βœ” Marketing Tools

πŸ”— https://shopify.pxf.io/Vxv09k


🌐 WordPress, WooCommerce & Jetpack

Create professional websites, blogs, and online stores with one of the most trusted web ecosystems in the world.

Ideal for:

βœ” Personal Blogs βœ” Portfolio Websites βœ” Business Websites βœ” eCommerce Stores

πŸ”— https://automattic.pxf.io/Z6vR5W


🌍 Language Learning Resources

πŸ—£οΈ Preply

Learn English and other languages through personalized one-on-one tutoring sessions with experts from around the world.

πŸ”— https://preply.sjv.io/o4gBDY


πŸ“š British Council English Online

Improve your professional communication skills and English fluency through structured learning programs.

πŸ”— https://englishonline.sjv.io/9VOGa4


🧠 Rosetta Stone

One of the most recognized language-learning platforms for immersive language acquisition.

πŸ”— https://aff.rosettastone.com/X4OyqG


πŸ§ͺ Science & Educational Resources

πŸ”¬ MEL Science

Interactive science kits and educational experiences designed to make STEM learning engaging and practical.

πŸ”— https://imp.i328067.net/bk2beg


πŸ“– Carson Dellosa Education

Educational materials and learning resources for students, teachers, and lifelong learners.

πŸ”— https://carsondellosaeducation.sjv.io/E0JbjW


❀️ Support My Work

Creating detailed technical content, tutorials, guides, and learning resources takes significant time and effort.

If you find my articles helpful and would like to support my work, you can do so through the following platforms:

⭐ Become a GitHub Sponsor

Support my open-source contributions, technical content, and community projects.

πŸ”— https://github.com/sponsors/hritikranjan1


β˜• Buy Me a Chai

Enjoying my content? Consider buying me a chai and supporting future tutorials, guides, and educational resources.

πŸ”— https://www.chai4.me/hritikranjan


πŸ‘¨β€πŸ’» Connect With Me

Hritik Ranjan

πŸ’‘ AI Enthusiast ☁️ DevOps Learner πŸ” Cybersecurity Advocate πŸ’» Software Developer

Connect & Follow

πŸ”— GitHub: https://github.com/hritikranjan1

πŸ”— LinkedIn: https://linkedin.com/in/hritikranjan1


πŸ“’ Found This Article Helpful?

If this article added value to your learning journey:

βœ… Share it with your network
βœ… Bookmark it for future reference
βœ… Follow for more DevOps, AI, Cloud, Cybersecurity, and Software Engineering content

Thank you for reading and being part of this learning journey.

Keep Learning. Keep Building. Keep Growing. πŸš€

🏷️ Suggested Tags for Hashnode

AWS
DevOps
CI/CD
AWS CodePipeline
AWS CodeDeploy
Amazon EC2
Docker
GitHub
Cloud
Python
Flask
Continuous Delivery

AWS for DevOps β˜οΈπŸš€

Part 12 of 14

Learn AWS from a DevOps Engineer's perspective. This series covers AWS fundamentals, IAM, EC2, VPC, S3, Route 53, Load Balancers, Auto Scaling, CloudWatch, ECS, EKS, CI/CD, Infrastructure as Code, Monitoring, Security, and real-world DevOps projects using AWS.

Up next

☁️ AWS CloudWatch Deep Dive | Monitor EC2, Logs, Metrics & CPU Alerts with SNS 🚨

Beginner-friendly notes on AWS CloudWatch with practical EC2 CPU monitoring and email alerts using Amazon SNS.

More from this blog

D

DevOps Journey by Hritik

33 posts

Started my DevOps journey from scratch, covering Linux, shell scripting, and a real-world AWS project for beginners.