Automated CI/CD pipeline from GitHub to AWS EC2
Zero-downtime Node.js deployments with CodePipeline, CodeDeploy, and shell lifecycle hooks
A production-ready CI/CD pipeline that automatically deploys a Node.js/Express API from GitHub to AWS EC2 using AWS CodePipeline and CodeDeploy. Includes lifecycle hooks for graceful stop/start, enabling zero-downtime deployments.
flowchart LR
GH[GitHub\nSource Push] --> CP[AWS CodePipeline\nOrchestrator]
CP --> CB[AWS CodeBuild\nBuild and Test]
CB --> CD[AWS CodeDeploy\nDeployment Agent]
CD --> S1[before_install.sh\nPrep environment]
S1 --> S2[application_stop.sh\nStop old process]
S2 --> S3[application_start.sh\nStart new version]
S3 --> EC2[AWS EC2\nNode.js Server Live]
style GH fill:#24292e,color:#fff,stroke:none
style CP fill:#FF9900,color:#fff,stroke:none
style CD fill:#FF9900,color:#fff,stroke:none
style EC2 fill:#232F3E,color:#fff,stroke:none
├── app.js # Express API entry point
├── package.json
├── appspec.yml # CodeDeploy lifecycle config
└── scripts/
├── before_install.sh # Install dependencies, prep environment
├── application_stop.sh # Gracefully stop running process
└── application_start.sh # Start new application version
- Push to GitHub — triggers CodePipeline automatically
- CodeBuild — installs dependencies and runs tests
- CodeDeploy — pulls the build artifact to the EC2 instance
- before_install.sh — prepares the server environment
- application_stop.sh — gracefully stops the current process
- application_start.sh — starts the new version
- AWS CodePipeline — multi-stage CI/CD orchestration
- AWS CodeDeploy — in-place deployment to EC2 with
appspec.yml - Lifecycle hooks —
BeforeInstall,ApplicationStop,ApplicationStart - Zero-downtime deploys — graceful process management
- Infrastructure as Code — all deployment config version-controlled in Git
- Fork or clone this repo
- Set up an EC2 instance with the CodeDeploy agent installed
- Create a CodePipeline connected to your GitHub repo
- Push a commit — the pipeline triggers automatically