Skip to content
Tech Trivandrum

Automated CI/CD Pipeline on AWS Using Docker, Terraform & ECS

Illustrative end-to-end AWS DevOps CI/CD architecture using GitHub, CodePipeline, CodeBuild, Docker, ECR, ECS Fargate, Terraform and CloudWatch.

DevOpsAmazon Web Services (AWS)GitHubAWS CodePipelineAWS CodeBuildDockerAmazon ECRAmazon ECS FargateApplication Load BalancerTerraformAmazon CloudWatchPython FlaskIAMAmazon VPC
Enquire About This Project
Automated CI/CD Pipeline on AWS Using Docker, Terraform & ECS – aws-devops-cover.jpg

Overview

Explore an illustrative AWS DevOps pipeline in which GitHub commits trigger CodePipeline, CodeBuild builds a Docker image, Amazon ECR stores it and Amazon ECS Fargate deploys the containerized application. Terraform is used conceptually for infrastructure provisioning and CloudWatch provides monitoring.

This is a conceptual learning project for the TechTrivandrum website. It does not claim that the application or infrastructure has been built, deployed or tested.

Illustrative project only

This package describes an educational AWS DevOps architecture. It is not presented as a deployed, tested or production-ready implementation.

Project objective

The goal is to demonstrate how modern DevOps services on AWS work together: source control, CI/CD orchestration, container image creation, registry publishing, container deployment, infrastructure as code, and monitoring.

Architecture diagram

Overall AWS architecture for the illustrative deployment.
Overall AWS architecture for the illustrative deployment.

The diagram shows the journey from a developer push in GitHub to a load-balanced application running on Amazon ECS Fargate. It also highlights VPC networking, IAM roles, secret management and CloudWatch observability.

Workflow diagram

Workflow from source code to deployment and monitoring.
Workflow from source code to deployment and monitoring.

Monitoring dashboard

Illustrative dashboard for pipeline and application health.
Illustrative dashboard for pipeline and application health.

A realistic DevOps pipeline needs visibility into build success, image publishing, deployment progress, service health and operational metrics. The sample dashboard visualizes those concepts in a clean educational format.

Illustrative sample application

app.pypython
from flask import Flask
app = Flask(__name__)

@app.get("/")
def index():
    return "Hello from TechTrivandrum illustrative AWS CI/CD demo!"

@app.get("/health")
def health():
    return {"status": "ok"}
Dockerfiledocker
FROM python:3.12-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY app.py .
EXPOSE 8080
CMD ["gunicorn", "--bind", "0.0.0.0:8080", "app:app"]

Build specification

CodeBuild can build a Docker image and output imagedefinitions.json for the standard ECS deployment action in CodePipeline. Environment variables and IAM permissions must be configured separately in a real setup.

buildspec.ymlyaml
version: 0.2
phases:
  pre_build:
    commands:
      - export REPOSITORY_URI="$AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME"
      - export IMAGE_TAG="${CODEBUILD_RESOLVED_SOURCE_VERSION:0:12}"
      - aws ecr get-login-password --region "$AWS_DEFAULT_REGION" | docker login --username AWS --password-stdin "$AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com"
  build:
    commands:
      - docker build -t "$REPOSITORY_URI:$IMAGE_TAG" .
  post_build:
    commands:
      - docker push "$REPOSITORY_URI:$IMAGE_TAG"
      - printf "[{\"name\":\"web\",\"imageUri\":\"%s\"}]" "$REPOSITORY_URI:$IMAGE_TAG" > imagedefinitions.json
artifacts:
  files:
    - imagedefinitions.json

Terraform excerpt

terraform/main.tfhcl
terraform {
  required_providers { aws = { source = "hashicorp/aws", version = "~> 5.0" } }
}
provider "aws" { region = var.aws_region }
variable "aws_region" { type = string }
resource "aws_ecr_repository" "app" {
  name                 = "techtrivandrum-cicd-demo"
  image_tag_mutability = "IMMUTABLE"
  image_scanning_configuration { scan_on_push = true }
}

Implementation notes

AreaIllustrative idea
Source controlGitHub repository containing application code and CI/CD definitions
Pipeline orchestrationAWS CodePipeline coordinates the build and deployment stages
Container buildAWS CodeBuild creates and tags the Docker image
Image registryAmazon ECR stores versioned container images
RuntimeAmazon ECS Fargate runs the containerized application
Traffic managementApplication Load Balancer routes requests and performs health checks
ObservabilityAmazon CloudWatch provides logs, metrics and alarms
Infrastructure as CodeTerraform conceptually provisions the main AWS resources

Security considerations

  • Use least-privilege IAM roles for CodePipeline, CodeBuild and ECS tasks.
  • Keep application containers in private subnets and expose only the load balancer.
  • Use HTTPS and secure secret storage such as AWS Secrets Manager or SSM Parameter Store.
  • Review image scanning, logging, alarms and deployment rollback settings before any real use.

Downloads

Download architecture guidePDF · 3 KBDownload illustrative sample codeZIP · 2 KB

More projects

Smart Server Room Monitoring using RaspberryPi – hero.png

Smart Server Room Monitoring using RaspberryPi

Illustrative Raspberry Pi IoT monitoring concept for server rooms, combining environmental sensors, door and power status, dashboard visualizations, historical records and configurable alerts.

  • Raspberry Pi 4
  • Python
  • Flask
  • SQLite
  • PostgreSQL (optional)
  • Chart.js
  • HTML
  • CSS
  • JavaScript
  • Bootstrap
  • GPIO
  • Telegram Bot API
  • SMTP