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 [email protected]:jsporna/fastapi-ecs-fargate.git
cd fastapi-ecs-fargate
Application 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.txt
next
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
or
make run
Application also can be run on localhost with docker
docker build -t fastapi-ecs-fargate .
docker run -p 8000:8000 fastapi-ecs-fargate
or
make docker-build
make docker-run
To 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 plan
In terminal will be printed a lot of new resources (33). Next let's apply it to AWS:
terraform apply