This is a demo application for AWS CodeDeploy deployment to EC2 instances. This project demonstrates how to deploy a Python FastAPI application using AWS CodeDeploy with GitHub as the source repository.
- FastAPI web application with counter functionality
- Automated deployment using AWS CodeDeploy
- Application lifecycle hooks (start/stop)
- Health check endpoint
- Docker containerization support
- Comprehensive logging and monitoring
- Backend: Python FastAPI application
- Deployment: AWS CodeDeploy with EC2 instances
- Source: GitHub repository
- Runtime: Python 3.8+ with virtual environment
- Containerization: Docker support for local development
- CodeDeploy downloads the application from GitHub
- Extracts the revision to the target directory
- Runs ApplicationStop hook to clean up previous deployment
- Runs ApplicationStart hook to start the new application
- Python 3.8+
- Docker (optional)
- Make (optional)
# Clone the repository
git clone <repository-url>
cd aws-codedeploy-ec2-demo
# Setup development environment
make dev-setup
source venv/bin/activate
make install
# Run the application
make run
# Build and run with Docker Compose
make docker-build
make docker-run
# View logs
make docker-logs
# Stop containers
make docker-stop
GET /
: Returns hello message with counter and uptimeGET /health
: Health check endpoint for monitoringGET /info
: Application information and status
aws-codedeploy-ec2-demo/
├── app.py # Main FastAPI application
├── requirements.txt # Python dependencies
├── appspec.yml # AWS CodeDeploy configuration
├── Dockerfile # Docker container definition
├── docker-compose.yml # Docker Compose configuration
├── Makefile # Development automation
├── scripts/
│ ├── applicationStart.sh # CodeDeploy start hook
│ ├── applicationStop.sh # CodeDeploy stop hook
│ └── health_check.sh # Health check script
└── README.md # This file
The appspec.yml
file configures:
- Application deployment destination
- File permissions and ownership
- Application lifecycle hooks
- Deployment timeout settings
- Built-in health check endpoint at
/health
- Application uptime tracking
- Background counter for demonstration
- Comprehensive logging
- Python 3.8+
- FastAPI
- Uvicorn
- AWS CodeDeploy agent (on target EC2 instances)
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.