AWS DevOps Engineer - Configuring Auto Scaling Group in CloudFormation Template

Configuring Auto Scaling Group in CloudFormation Template

Prev Question Next Question

Question

As a DevOps engineer, you are helping the development team to set up a CI/CD pipeline.

The new application should be deployed in an ECS cluster with a CloudFormation stack.

In the CloudFormation YAML file, you need to include AWS resources of an ECS Cluster, a Launch template, an Auto Scaling group and so on.

The Auto Scaling group instances should be registered in the ECS Cluster.How would you configure the ASG in the CloudFormation template?

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D.

Correct Answer - C.

For the CloudFormation example of ECS, please check https://github.com/aws-samples/ecs-refarch-cloudformation/blob/master/infrastructure/ecs-cluster.yaml.

The ECS_CLUSTER environment parameter should be configured in the /etc/ecs/ecs.config file according to.

https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-agent-config.html.

Option A is incorrect: Because for ECS Fargate, users do not need to manage ECS instances such as Auto Scaling groups by themselves.

Option B is incorrect: Because in the CloudFormation Auto Scaling group resource, there is no ECS Cluster property.

Option C is CORRECT: Because this is the correct way to register the instances.

The below command is an example:

!Sub echo ECS_CLUSTER=${ECSCluster} >> /etc/ecs/ecs.config.

Option D is incorrect: Because the “DependsOn: ECSCluster” property only determines the sequence of resources to be launched.

It does not register the instances with the ECS Cluster.

When configuring an Auto Scaling group (ASG) in a CloudFormation template to deploy an application on an ECS cluster, it is necessary to ensure that the ASG instances are registered with the ECS cluster.

Option A, which suggests using the ECS Fargate resource to automatically register ASG instances with the ECS Cluster, is incorrect. Fargate is a serverless compute engine that runs containers, and it is not relevant to this scenario.

Option B, which suggests adding the ECS Cluster property to the ASG resource, is the correct answer. The ECS_CLUSTER property specifies the name of the ECS cluster that the ASG instances should be registered with. When the ASG launches or terminates instances, they will be automatically registered or deregistered with the specified ECS cluster.

Option C, which suggests adding the ECS_CLUSTER environment parameter in the Launch template metadata, is incorrect. While it is possible to pass environment variables to an ECS container instance via the /etc/ecs/ecs.config file, this approach is not required to register ASG instances with the ECS cluster.

Option D, which suggests adding the "DependsOn" property to associate the ASG with the ECS Cluster, is incorrect. While the "DependsOn" property can be used to ensure that CloudFormation resources are created in a specific order, it is not relevant to this scenario as it does not address the registration of ASG instances with the ECS cluster.

Therefore, the correct answer to the question is Option B. In the Auto Scaling group resource, add the ECS_CLUSTER property (ECS_CLUSTER: ${ECSCluster})to register the ASG with the ECS Cluster.