A simple Flask web application that serves "Hello, World!" with Docker containerization and AWS deployment capabilities.
- ✅ Flask web application with a simple "Hello, World!" endpoint
- ✅ Production-ready Gunicorn WSGI server
- ✅ Docker containerization with
python:3.12-slim
base image - ✅ Docker Compose for local development
- ✅ GitHub Actions CI/CD pipeline for AWS ECR and Elastic Beanstalk deployment
-
Clone the repository
git clone https://github.com/jslmariano/python-hello.git cd python-hello
-
Install dependencies
pip install -r requirements.txt
-
Run the Flask development server
python app.py
The app will be available at
http://localhost:5000
-
Run with Gunicorn (production-like)
gunicorn -b 127.0.0.1:8000 wsgi:application --workers 2 --timeout 120
The app will be available at
http://localhost:8000
-
Build and run with Docker
docker build -t python-hello-app . docker run -p 8000:8000 python-hello-app
-
Or use Docker Compose
docker compose up
The app will be available at
http://localhost:8000
Before deploying to AWS, ensure you have:
- AWS Account with appropriate permissions
- ECR Repository created named
python-hello
- Elastic Beanstalk Application and environment set up
- GitHub Secrets configured:
AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY
The CI/CD pipeline automatically:
- On every push to main: Builds and pushes Docker image to AWS ECR
- On manual workflow dispatch: Additionally deploys to Elastic Beanstalk
To trigger deployment:
- Go to GitHub Actions in your repository
- Select "Build and Deploy to AWS ECR and Elastic Beanstalk" workflow
- Click "Run workflow"
- Check "Deploy to Elastic Beanstalk" option
- Click "Run workflow"
If you prefer manual deployment:
-
Configure AWS CLI
aws configure
-
Build and push to ECR
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin <account-id>.dkr.ecr.us-east-1.amazonaws.com docker build -t python-hello . docker tag python-hello:latest <account-id>.dkr.ecr.us-east-1.amazonaws.com/python-hello:latest docker push <account-id>.dkr.ecr.us-east-1.amazonaws.com/python-hello:latest
-
Create Dockerrun.aws.json for Elastic Beanstalk
{ "AWSEBDockerrunVersion": "1", "Image": { "Name": "<account-id>.dkr.ecr.us-east-1.amazonaws.com/python-hello:latest", "Update": "true" }, "Ports": [ { "ContainerPort": 8000, "HostPort": 80 } ] }
-
Deploy to Elastic Beanstalk
zip deploy.zip Dockerrun.aws.json aws elasticbeanstalk create-application-version --application-name python-hello --version-label v1 --source-bundle S3Bucket=<your-s3-bucket>,S3Key=deploy.zip aws elasticbeanstalk update-environment --environment-name python-hello-env --version-label v1
python-hello/
├── app.py # Flask application
├── wsgi.py # WSGI entry point for Gunicorn
├── requirements.txt # Python dependencies
├── Dockerfile # Docker container configuration
├── docker-compose.yml # Docker Compose configuration
├── .gitignore # Git ignore rules
├── .github/
│ └── workflows/
│ └── deploy.yml # GitHub Actions CI/CD pipeline
└── README.md # This file
FLASK_ENV
: Set toproduction
for production deployments (default in Docker)
- Base Image:
python:3.12-slim
- Port:
8000
- Gunicorn Configuration: 2 workers, 120s timeout
- Command:
gunicorn -b 0.0.0.0:8000 wsgi:application --workers 2 --timeout 120
Update the following values in .github/workflows/deploy.yml
as needed:
AWS_REGION
: AWS region (default:us-east-1
)ECR_REPOSITORY
: ECR repository name (default:python-hello
)EB_APPLICATION_NAME
: Elastic Beanstalk app name (default:python-hello
)EB_ENVIRONMENT_NAME
: Elastic Beanstalk environment (default:python-hello-env
)
- Flask 3.0.0: Web framework
- Gunicorn 23.0.0: Production WSGI server (security patched version)
This application uses the latest patched versions of all dependencies to ensure security best practices.
This project is open source and available under the MIT License.