In this lab you will create the the application running on ECS Fargate cluster together with Application Loadbalancer. Application will be deploying in Docker container from docker hub repository.
In this task you will create CloudFormation stack with ECS Fargate cluster and Application Loadbalancer. You will use CloudFormation template stored in S3 bucket.
The template containe Parameters section.. Thanks to this you will be able to provide some information during stack creation.
Look at the floowing example:
Parameters:
VPC:
Type: AWS::EC2::VPC::Id
SubnetA:
Type: AWS::EC2::Subnet::Id
SubnetB:
Type: AWS::EC2::Subnet::Id
Image:
Type: String
Default: kaminskypavel/mario
ServiceName:
Type: String
# update with the name of the service
Default: awsninjax-sn
ContainerPort:
Type: Number
Default: 8080
LoadBalancerPort:
Type: Number
Default: 8080
HealthCheckPath:
Type: String
Default: /
HostedZoneName:
Type: String
Default: labs.piratescloud.com- On the Services search menu, click Cloud Formation.
- Click Create stack and With new resources (standard).
- For Prepare template select Choose an existing template.
- For Template source use Amazon S3 URL and paste url for cloudformation template:
https://lukado-public.s3.eu-west-1.amazonaws.com/labs/template-ecs-mario.yaml- Click Next.
- Provide following informations:
- Stack name: awsninjaX-stack
- ServiceName: awsninjaX-sn
- Subdomain: awsninja20X
- VPC: Use your VPC
- SubnetA: Select your Public1 subnet
- SubnetB: Select your Public2 subnet
- Click Next.
- Scroll down to the Capabilities and mark selection for I acknowledge that AWS CloudFormation might create IAM resources with custom names.
- Click Next.
- Click Submit.
Wait until stack is in state CREATE_COMPLETE. You can observe the progress in Events - updated tab. You can choose Table view or newly added Timeline view.
In the meantime lets review resources defined in the template. Every resource is defined in Resources section.
Resources:Below you can see a definition of the ECS Cluster
Resources:
Cluster:
Type: AWS::ECS::Cluster
Properties:
ClusterName: !Join ['', [!Ref ServiceName, Cluster]]
As you can see the Cluster name is defined as a combination of ServiceName and Cluster. ServiceName is a parameter defined in Parameters section.
For the name creation we use Join function. This function is used to join two or more strings together. In this case we join ServiceName and Cluster with empty string.
Additionall we can see that we use Ref function to get value of ServiceName parameter.
Bellow is a piece of code for TaskDefinition resource.
TaskDefinition:
Type: AWS::ECS::TaskDefinition
# Makes sure the log group is created before it is used.
DependsOn: LogGroup
Properties:
# Name of the task definition. Subsequent versions of the task definition are grouped together under this name.
Family: !Join ['', [!Ref ServiceName, TaskDefinition]]
# awsvpc is required for Fargate
NetworkMode: awsvpc
RequiresCompatibilities:
- FARGATEHere you can find another parameter called DependsOn. This parameter is used to define dependencies between resources. In this case we define that TaskDefinition resource depends on LogGroup resource. This means that LogGroup resource will be created before TaskDefinition resource.
Let look at the Outputs section.
Outputs:
Endpoint:
Description: Endpoint
Value: !Join ['', ['http://', !Ref DNSRecord,':8080']]With the Outputs section we can define values that will be displayed after stack creation. In this case we define Endpoint value. This value is a combination of DNSRecord and 8080 port.
You can also use Outputs section to export values to other stacks. This is very useful when you want to use values from one stack in another stack.
OK, let go back to our stack creation. If the stack is in state CREATE_COMPLETE you can go to the next task.
Let try to examine our stack. We will look into Events, Outputs, Resources and Parameters sections.
- Find your stack and click on its name.
- Look into sections by selecting proper tab:
Resource
Here you can see all resources that were created during stack creation. You can also see their status and some additional information. You can use search field to find specific resource.
Events
Here you can see all events that were generated during stack creation. You can also see their status and some additional information. You can use search field to find specific event.
This is a good place to look for errors if something went wrong during stack creation. When something went wrong you should look here for the first event with status FAILED. This event will contain information about the error.
Parameters
Here you can see all parameters that were used during stack creation. You can also see their values. This is a good place to look for parameters values if you don't remember them, or need to use them in another stack.
Outputs
Here you can see all outputs that were defined in the template. You can also see their values.
- Click on Outputs section and click on the generated Endpoint url.
- Take the url and paste it into your browser.
Enjoy your game...😎
Let go back to the AWS Console and review deployed configuration.
- On the Services search menu, click ECS.
- Click on Clusters.
- Click on awsninjaX-cluster.
- Click on Tasks.
As you can see task is in RUNNING state. This means that our container is running on ECS Fargate cluster.
All of these resources were created by CloudFormation stack.
- On the Services search menu, click EC2.
- Click on Load Balancers.
- Try to find a load balancer created by CloudFormation stack.
- On the Services search menu, click Route53.
- Click on Hosted zones.
- Select your hosted zone.
- Try to find a record created by CloudFormation stack.
What type of record is it?
- Back in CloudFormation console select your stack by checking the checkmark left to its name.
- Click Delete.
- Click Delete stack.
© 2026 lukado.eu
