AWS CloudFormation: 05 - Create a web server Docker instance
This is continued from AWS CloudFormation: 04 – Build and deploy pipeline .
Background
I want a web server Docker instance.
What we need?
- A VPC with 2 subnets because we need to have a load balancer also.
- A load balancer so we can have a fixed endpoint with flexible Docker instances.
- A container cluster to host the Docker web server.
- A container task definition to tell how to run the Docker web server.
How to do it?
This is what we are going to do:

Open 02-autoscaling-template.yaml from previous post and save as 05-container-webserver-template.yaml .
Unwanted Resources
We don't need all the resources from the previous YAML file, so we need to do some cleanup first. Delete these resources
- WebServerLaunchTemplate
- WebServerAutoScalingGroup
We don't need the SSH access also, so delete the port 22 from the WebServerSecurityGroup.
Load Balancer
The previous load balancer is setup to work with EC2 instances. We need to change it to work with Docker instances. Change this resource:
1 |
WebServerLoadBalancerTargetGroup:
|
Change the TargetType to ip so it works with Docker instances. |
Container
We need to setup to container. We will use AWS Fargate service. It will handle all the Docker services for us. We just need to setup the container task definition. Add these resources:
1 |
WebServerContainerCluster:
|
The container cluster. |
2 |
WebServerContainerTaskDefinition:
|
The container task definition. |
3 |
WebServerContainerService:
|
Launch the container into the cluster. |
Parameters
We have removed the SSH access to the Docker instance. We don't need any parameters here, so just remove all.
The URL to the load balancer is available at the Outputs section. Update the stack then you should be able to see the NGINX test page with the load balancer URL.