CI / CD exercise for Python FastAPI on AWS with ECS Fargate + ALB
Repository contains:
- application in Python (FastAPI),
- docker image description (Dockerfile)
- infrastructure as code for AWS
Get code of repo:
git clone git@github.com:jsporna/fastapi-ecs-fargate.git
cd fastapi-ecs-fargateApplication is simple FastAPI Hello World code to show usage of docker in AWS. There is also dummy test for CI test job. Application can be run on localhost with virtual environment approach.
python3 -m venv venv
source venv/bin/activate
pip install -r dev-reqirements.txtnext
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000or
make runApplication also can be run on localhost with docker
docker build -t fastapi-ecs-fargate .
docker run -p 8000:8000 fastapi-ecs-fargateor
make docker-build
make docker-runTo build own AWS infrastructure you need:
- terraform,
- AWS account (free tier is good enough)
- AWS CLI
First prepare configuration for aws-cli -> LINK When it is ready let's create some infrastructure in Cloud
cd iac
terraform init
terraform planIn terminal will be printed a lot of new resources (33). Next let's apply it to AWS:
terraform apply