Skip to content

Latest commit

 

History

8 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AWS CI/CD Pipeline (CodeBuild + CodeDeploy + EC2)

A Java web application with a fully automated AWS CI/CD pipeline. Source code changes trigger an automated build via AWS CodeBuild, which compiles and packages the application as a WAR file, then AWS CodeDeploy handles automated deployment to an EC2 instance running Tomcat — no manual deployment steps required.

Pipeline Architecture

GitHub Push
    │
    ▼
AWS CodePipeline
    │
    ├──► AWS CodeBuild
    │       • Pulls auth token from AWS CodeArtifact
    │       • Compiles Java source (Maven + Corretto 8)
    │       • Packages as .WAR file
    │       • Outputs: WAR + appspec.yml + deployment scripts
    │
    └──► AWS CodeDeploy
            • Stops existing Tomcat service
            • Deploys WAR to /usr/share/tomcat/webapps/
            • Restarts Tomcat service
            • Runs on EC2 (Linux)

Tech Stack

Layer Technology
Application Java (Corretto 8), Maven
Build AWS CodeBuild
Artifact Storage AWS CodeArtifact
Deployment AWS CodeDeploy
Hosting AWS EC2 (Linux + Tomcat)
Pipeline Orchestration AWS CodePipeline
IaC Config buildspec.yml, appspec.yml

Repository Structure

nextwork-web-project/
├── src/main/webapp/       # Java web application source
├── scripts/
│   ├── install_dependencies.sh   # CodeDeploy: BeforeInstall hook
│   ├── start_server.sh           # CodeDeploy: ApplicationStart hook
│   └── stop_server.sh            # CodeDeploy: ApplicationStop hook
├── buildspec.yml          # AWS CodeBuild build instructions
├── appspec.yml            # AWS CodeDeploy deployment specification
├── pom.xml                # Maven project configuration
└── settings.xml           # Maven settings (CodeArtifact repo config)

Key Files Explained

buildspec.yml

Defines the three-phase CodeBuild process:

  • Install: Sets Java runtime to Corretto 8
  • Pre-build: Authenticates with AWS CodeArtifact to pull private dependencies
  • Build: Compiles with mvn compile, then packages with mvn package
  • Artifacts: Exports the WAR file, appspec.yml, and deployment scripts for CodeDeploy

appspec.yml

Tells CodeDeploy exactly how to deploy the artifact:

  • Copies the WAR to Tomcat's webapps directory
  • Runs lifecycle hooks: stop server → install dependencies → start server

scripts/

Shell scripts executed by CodeDeploy during deployment lifecycle hooks — handles Tomcat service management and dependency installation on the EC2 instance.

Key Concepts Demonstrated

  • AWS CodePipeline: End-to-end pipeline orchestration from source to production
  • AWS CodeBuild: Managed build environment — no build servers to maintain
  • AWS CodeArtifact: Private Maven repository with token-based authentication
  • AWS CodeDeploy: Automated, scripted deployment with lifecycle hooks
  • EC2 + Tomcat: Java web app hosting with controlled start/stop deployment process
  • Deployment Lifecycle Hooks: BeforeInstall → ApplicationStart → ApplicationStop

Prerequisites to Run This Pipeline

  • AWS account with CodePipeline, CodeBuild, CodeDeploy, and CodeArtifact configured
  • EC2 instance with CodeDeploy agent installed and Tomcat running
  • IAM roles with appropriate permissions for each service
  • CodeArtifact domain named nextwork set up in us-east-1

What I'd Add Next

  • Blue/green deployment strategy via CodeDeploy to achieve zero-downtime releases
  • Automated rollback trigger on deployment failure
  • CloudWatch alarms and SNS notifications on build/deploy failures
  • Terraform to provision the EC2 instance, IAM roles, and pipeline infrastructure as code

About

Java web app with a full AWS CI/CD pipeline — CodeBuild compiles and packages the WAR, CodeDeploy deploys to EC2 automatically

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages