This repository provisions a complete delivery path for the
random-actor Flask application on
AWS.
The final architecture is intentionally focused on one deployment model: Docker on EC2, delivered through CodePipeline and CodeDeploy.
tabebill/random-actor
|
v
CodePipeline
|
v
CodeBuild
- builds Docker image
- pushes image to ECR
- packages CodeDeploy bundle
|
v
Manual approval
|
v
CodeDeploy
|
v
EC2 Auto Scaling Group
|
v
Application Load Balancer
The Flask app listens on port 5001 inside the container. During deployment,
the container is started with an 80:5001 mapping so the Application Load
Balancer can serve it over HTTP on port 80.
Terraform provisions:
- a VPC with two public subnets
- an Application Load Balancer, listener, and target group
- an EC2 Auto Scaling Group with Docker and the CodeDeploy agent installed
- an ECR repository for application images
- CodeBuild, CodeDeploy, and CodePipeline resources
- an S3 artifact bucket and DynamoDB lock table
- the IAM roles and policies needed by the pipeline and EC2 instances
- a CodeStar connection resource for GitHub integration
- A change is pushed to the
random-actorbranch oftabebill/random-actor. - CodePipeline pulls the application source through the GitHub connection.
- CodeBuild:
- builds the Docker image,
- pushes it to ECR,
- creates a CodeDeploy revision bundle containing:
appspec.ymlimage.env- deployment scripts
- A manual approval stage pauses the release.
- CodeDeploy deploys the approved image to the EC2 Auto Scaling Group.
- The Application Load Balancer routes traffic to the running containers.
.
├── .github/workflows/deploy.yml
├── terraform/
│ ├── main.tf
│ ├── locals.tf
│ ├── outputs.tf
│ └── modules/
│ ├── codepipeline/
│ ├── ec2-codedeploy/
│ ├── image-codebuild/
│ ├── tf-state/
│ └── vpc/
Before applying the Terraform, you need:
- an AWS account with permissions to create IAM, EC2, ALB, ECR, S3, DynamoDB, CodeBuild, CodeDeploy, CodePipeline, and CodeStar Connection resources
- Terraform installed locally
- AWS credentials configured locally, or AWS credentials added as GitHub
Actions secrets:
AWS_ACCESS_KEY_IDAWS_SECRET_ACCESS_KEY
From the repository root:
cd terraform
terraform init
terraform plan
terraform applyAfter the first apply:
- Open the AWS console.
- Find the newly created CodeStar connection.
- Complete the pending GitHub authorization flow.
- Make sure the connection can access
tabebill/random-actor.
The CodeStar connection is created by Terraform, but AWS still requires the GitHub authorization handshake to be completed manually once.
The workflow in .github/workflows/deploy.yml runs Terraform when changes are
pushed to this repository's cicd branch.
After a successful apply, Terraform returns:
alb_dns_name— public DNS name of the load balancerecr_repository_url— ECR repository used for application imagescodestar_connection_arn— GitHub connection ARN created for CodePipeline
- The pipeline source is the application repository, not this Terraform repository.
- Elastic Beanstalk is not part of the final design.
- The deployment bundle is generated during the CodeBuild stage so the exact image that was built is the image CodeDeploy later rolls out.