Create Auto Scaling Group with AWS CLI - Step-by-Step Guide

Create Auto Scaling Group with AWS CLI

Prev Question Next Question

Question

You have a launch template where a subnet is specified in its network interface.

Now you need to use AWS CLI (aws autoscaling create-auto-scaling-group) to create an Auto Scaling group with the launch template.

However, the ASG should be launched in another subnet that is different from the one specified in the launch template.

How would you create the ASG with the AWS CLI command?

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D.

Correct Answer - C.

Option A is incorrect: Because the subnet in the launch template is ignored when creating an Auto Scaling group.

The subnet needs to be specified in AWS CLI (AWS autoscaling create-auto-scaling-group).

Option B is incorrect: Because the subnet should be specified in the --vpc-zone-identifier option of AWS CLI.

Option C is CORRECT: When creating the ASG using AWS CLI command, the subnets should be specified in the --vpc-zone-identifier option.

Option D is incorrect: Because there is no need to create a new launch template.

You just need to specify the subnet in the --vpc-zone-identifier option.

Reference:

https://docs.aws.amazon.com/autoscaling/ec2/userguide/create-launch-template.html https://docs.aws.amazon.com/autoscaling/ec2/userguide/create-asg-launch-template.html https://docs.aws.amazon.com/cli/latest/reference/autoscaling/create-auto-scaling-group.html

The correct answer is B. Change the subnet in the launch template. In AWS CLI (aws autoscaling create-auto-scaling-group), specify the subnet through the --launch-template option.

Explanation:

When you create an Auto Scaling group using a launch template, the settings in the launch template are used as a blueprint for the instances launched by the Auto Scaling group. The launch template contains the configuration details, such as the AMI, instance type, and network settings, that the Auto Scaling group uses to launch EC2 instances.

When launching an instance using a launch template, you can specify the subnet that the instance should be launched in. If you want to launch an Auto Scaling group in a different subnet than the one specified in the launch template, you can change the subnet in the launch template and create a new version of the launch template. However, this is not the recommended approach, as it changes the launch template, which could affect other Auto Scaling groups that use the same launch template.

Instead, you should use the --launch-template option in the AWS CLI (aws autoscaling create-auto-scaling-group) command to specify the launch template to use and override the subnet specified in the launch template. You can pass the ID of the launch template and the subnet ID to launch the instances in the desired subnet. For example, the command would look like:

sql
aws autoscaling create-auto-scaling-group \ --auto-scaling-group-name MyASG \ --launch-template LaunchTemplateId=lt-0123456789abcdef,Version=1 \ --vpc-zone-identifier subnet-0123456789abcdef

In this example, the launch template with the ID lt-0123456789abcdef and version 1 is used to launch instances, but the instances are launched in the subnet with the ID subnet-0123456789abcdef. The subnet specified in the launch template is ignored.

Option C, specifying the subnet through the --vpc-zone-identifier option, is also correct, but it is less flexible than option B, as it does not allow you to specify other launch template settings, such as the instance type or security group, in the CLI command. Option A, modifying the launch template, and option D, creating another launch template, are both incorrect, as they modify the launch template, which could affect other Auto Scaling groups that use the same launch template.