Basic Express.js web app used to demonstrate containerisation of a web app and deployment to AWS Elastic Container Registry (ECR).
- Install Docker for Mac
- Make the docker-task bash file executable by running:
chmod +x ./docker-task.sh
- You have an existing AWS account and the AWS CLI installed.
Create ECR Repository
This will create a new repository using the name of the Docker image (in this case it's
Note down the value of the
repositoryUri field printed in the console.
You can then open the ECR Console to verify that is was created.
Build Docker image
Run container locally
Open a browser to http://localhost:9999/ and verify that "Hello world" is displayed.
Deploy image to ECR
- Open the
docker-task.shfile and edit the
REPOSITORY_PATHvariable and set it to the path of your ECR. It should look something like
<aws_account_id>.dkr.ecr.<aws_region>.amazonaws.com. It will be the first part of the
repositoryUrivalue noted down in the CreateRepo step.
- Save the file and then run
This will upload your file to the ECS repository. You should be able to view it in the AWS Console.
## Deploy CloudFormation Stack
Open your terminal and run the CLI command below to create your stack. Before running it, you will need to update all values surrounded by angle brackets, e.g. (
aws cloudformation deploy \ --stack-name SimpleExpressApp \ --template-file ./cloudformation/ecs-webapp-stack.yml \ --capabilities CAPABILITY_IAM \ --parameter-overrides KeyName='<your_keypair_id>' \ VpcId='<your_vpc_id>' \ SubnetId='<your_subnet_id_1>,<your_subnet_id_2>' \ ContainerPort=8080 \ DesiredCapacity=2 \ EcsImageUri='<your_ecr_image_uri>' \ EcsImageVersion='<your_app_version_number>' \ InstanceType=t2.micro \ MaxSize=3