Signup Demo Application
This application uses Python's Flask framework, NGINX and uWSGI daemon
This Python sample application is based on the eb-py-flask-signup sample. It has been modified to run on Amazon EC2 Container Service (ECS).
Local run
To run / debug locally from your laptop
cd code/signup-flask-nginx-docker
pipenv shell
pipenv install
python3 application.py
Docker build & run
To run on a docker container on your lapptop
cd code
docker build -t demo-flask-signup:latest .
docker run -p 8080:80 --rm -v ~/.aws:/root/.aws demo-flask-signup:latest
Push the image to ECR (optional)
REGION=us-west-2
# Create repository - one time operation
aws ecr create-repository --region $REGION --repository-name demo-flask-signup
# Authenticate - once every 12h
aws ecr get-login-password --region $REGION | docker login --username AWS --password-stdin 486652066693.dkr.ecr.$REGION.amazonaws.com
# Build and tag
docker build -t demo-flask-signup .
docker tag demo-flask-signup:latest 486652066693.dkr.ecr.$REGION.amazonaws.com/demo-flask-signup:latest
# Push to the repository
docker push 486652066693.dkr.ecr.us-west-2.amazonaws.com/demo-flask-signup:latest
Deploy on Lightsail
Install Lightsail CLI plugin
Install the lightsail CLI plugin for AWS CLI, as per instructions at https://lightsail.aws.amazon.com/ls/docs/en_us/articles/amazon-lightsail-install-software
Create a Lightsail service
aws lightsail create-container-service --region eu-west-3 --service-name signup-application --power nano --scale 1
{
"containerService": {
"containerServiceName": "test",
"arn": "arn:aws:lightsail:us-west-2:486652066693:ContainerService/ade696e8-e809-4420-a66c-ec62de041df5",
"createdAt": "2021-07-17T13:34:14+02:00",
"location": {
"availabilityZone": "all",
"regionName": "us-west-2"
},
"resourceType": "ContainerService",
"tags": [],
"power": "nano",
"powerId": "nano-1",
"state": "PENDING",
"scale": 1,
"isDisabled": false,
"principalArn": "",
"privateDomainName": "test.service.local",
"url": "https://test.7fl0nk3t0f4bo.us-west-2.cs.amazonlightsail.com/"
}
}
aws lightsail get-container-services --region eu-west-3 --service-name signup-application --query "containerServices[].state"
Push a container image
aws lightsail push-container-image --region us-west-2 --service-name demo-signup --label latest --image demo-flask-signup:latest
Create a deployment
lc.json file
{
"serviceName": "demo-signup",
"containers": {
"demo-signup": {
"image": ":demo-signup.latest.2",
"ports": {
"80": "HTTP"
}
}
},
"publicEndpoint": {
"containerName": "demo-signup",
"containerPort": 80
}
}
aws lightsail create-container-service-deployment --cli-input-json file://lc.json
aws lightsail get-container-services --query "containerServices[].nextDeployment"