Run the application in ECS container using CloudFormation for deployment.
See ./documentation/infrastructure-diagram.png
This approach provides a unified scalable way to deploy stateless applications. Usage of dockers ensures that the result of deployment would be the same all the time.
- The Application is running in ECS instances in private Network
- Access to instances is protected by and are protected AWS Security Group.
- The Application is running inside the Docker container that provides the additional level of security.
- Access to LoadBalancer is protected by AWS Security Group.
- You can easily scale up and down the application using Auto-scalable Group based on different triggers ( HTTP-error-500, CPU-load .. etc..)
- The application can be launched in two or more nodes and in different availability zones.
Selected deployment tool CloudFormation is AWS native tool that provides the highest compatibility with AWS API.
- Part 1: Create an ECS Registry for application, build Docker image and upload it to the registry.
- Part 2: Deploy docker application on ECS Cluster.
- Create ECS Repository.
- Build docker image locally.
- Upload created image to ECS Repository.
- Create ESC Container stack using CloudFormation
- Retrieve URL (using script or via AWS Console)
-
You can either AWS Console and template files ECS_Repository.json and ECS_EC2_Cluster.json from infrastructure/aws/cloudformation/template directory to create stacks manually
-
Or create/update configuration file (config.ini). Set valid variables for your AWS account:
KeyName, VpcId, LoadBalancerSubnetId, InstanceSubnetId
.
And use./install.sh
script to simplify deployment . See installation steps bellow.
-
Next packages must be installed locally to be able to deploy the application:
- awscli
- git
- docker (docker.io)
- jq
-
AWSCli needs to be configured: Use
aws configure
command. -
Permissions:
- Make sure the curent useer have permissions to run docker (Is member of 'docker' group).
- CloudFormation stack require lot of different permissions to create different resources. Use Admin account in order to simplify installation.
Let pretend we want to deploy application using name "simple-sinatra-app1"
Use ./install.sh -h
for help.
Run ./install.sh -n simple-sinatra-app1 -a create-repo
./install.sh -n simple-sinatra-app1 -a create-image
./install.sh -n simple-sinatra-app1 -a upload-image
./install.sh -n simple-sinatra-app1 -a create-cluster
Run `./install.sh -n simple-sinatra-app1 -a info
# To install another stack using existed image
./install.sh -n simple-sinatra-app2 -a create-cluster -i <aws-accunt-id>.dkr.ecr.us-east-1.amazonaws.com/simple-sinatra-app1:latest
./install.sh -n simple-sinatra-app1 -a delete-cluster
./install.sh -n simple-sinatra-app1 -a delete-repo