Deploy Flask on AWS with GitHub Actions

๐Ÿงช Flask โ˜๏ธ Amazon Web Services โš™๏ธ GitHub Actions

Configuration Files

2 files
Production-ready configuration files with detailed comments and best practices. Each file works together as a complete deployment solution.
Flask production Dockerfile
dockerfile
FROM python:3.11-slim

WORKDIR /app

# Install dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy application
COPY . .

# Run as non-root user
RUN useradd -m flask && chown -R flask:flask /app
USER flask

EXPOSE 5000

CMD ["gunicorn", "--bind", "0.0.0.0:5000", "--workers", "4", "app:app"]
Flask dependencies
text
Flask==3.0.0
gunicorn==21.2.0
python-dotenv==1.0.0

Prerequisites

  • AWS account with ECS and ECR
  • GitHub repository
  • Flask application ready

Deployment Steps

  • Create ECR repository for Flask app
  • Set up ECS cluster and task definition
  • Configure environment variables
  • Add AWS credentials to GitHub Secrets
  • Push to main to deploy

Additional Notes

  • Use gunicorn for production WSGI server
  • Configure Flask environment to production
  • Use environment variables for secrets
  • Consider using Application Load Balancer