Attach a VPC Lattice target group to your Amazon EC2 Auto Scaling group
This topic describes how to attach a VPC Lattice target group to an Amazon EC2 Auto Scaling group. It also describes how to turn on VPC Lattice health checks to let Amazon EC2 Auto Scaling replace instances that VPC Lattice reports as unhealthy.
By default, Amazon EC2 Auto Scaling only replaces instances that are unhealthy or unreachable based on Amazon EC2 health checks. If you turn on VPC Lattice health checks, Amazon EC2 Auto Scaling can replace a running instance if any of the VPC Lattice target groups you attach to the Amazon EC2 Auto Scaling group report it as unhealthy. For more information, see Health checks for instances in an Amazon EC2 Auto Scaling group.
Important
Before you continue, complete all prerequisites in the previous section.
Attach a VPC Lattice target group
You can attach one or more target groups to an Amazon EC2 Auto Scaling group when you create or update the group.
- Console
-
Follow the steps in this section to use the console to:
-
Attach a VPC Lattice target group to an Amazon EC2 Auto Scaling group
-
Turn on the health checks for VPC Lattice
To attach a VPC Lattice target group to a new Amazon EC2 Auto Scaling group
Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/
, and choose Amazon EC2 Auto Scaling Groups from the navigation pane. -
On the navigation bar at the top of the screen, choose the AWS Region that you created your target group in.
-
Choose Create Amazon EC2 Auto Scaling group.
-
In steps 1 and 2, choose your desired options and proceed to Step 3: Configure advanced options.
-
For VPC Lattice integration options, choose Attach to VPC Lattice service.
-
Under Choose VPC Lattice target group, choose your target group.
-
(Optional) For Health checks, Additional health check types, select Turn on VPC Lattice health checks.
-
(Optional) For Health check grace period, enter the amount of time, in seconds. This amount of time is how long Amazon EC2 Auto Scaling needs to wait before checking the health status of an instance after it enters the
InServicestate. For more information, see Set the health check grace period for an Amazon EC2 Auto Scaling group. -
Proceed to create the Amazon EC2 Auto Scaling group. Your instances will be automatically registered to the VPC Lattice target group after the Amazon EC2 Auto Scaling group has been created.
To attach a VPC Lattice target group to an existing Amazon EC2 Auto Scaling group
Use the following procedure to attach a target group for a service to an existing Amazon EC2 Auto Scaling group.
Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/
, and choose Amazon EC2 Auto Scaling Groups from the navigation pane. -
Select the check box next to your Amazon EC2 Auto Scaling group.
A split pane opens up in the bottom of the page.
-
On the Details tab, choose VPC Lattice integration options, Edit.
-
Under VPC Lattice integration options, choose Attach to VPC Lattice service.
-
Under Choose VPC Lattice target group, choose your target group.
-
Choose Update.
When you finish attaching the target group, you can optionally turn on the health checks that use it.
To turn on the VPC Lattice health checks
-
On the Details tab, choose Health checks, Edit.
-
For Health checks, Additional health check types, select Turn on VPC Lattice health checks.
-
For Health check grace period, enter the amount of time, in seconds. This amount of time is how long Amazon EC2 Auto Scaling needs to wait before checking the health status of an instance after it enters the
InServicestate. For more information, see Set the health check grace period for an Amazon EC2 Auto Scaling group. -
Choose Update.
-
- AWS CLI
-
Follow the steps in this section to use the AWS CLI to:
-
Attach a VPC Lattice target group to an Amazon EC2 Auto Scaling group
-
Turn on the health checks for VPC Lattice
To attach a VPC Lattice target group to an Amazon EC2 Auto Scaling group
Use the following create-auto-scaling-group
command to create an Amazon EC2 Auto Scaling group and simultaneously attach a VPC Lattice target group by specifying its Amazon Resource Name (ARN). Replace the sample values for
--auto-scaling-group-name,--vpc-zone-identifier,--min-size, and--max-size. For the--launch-templateoption, replaceandmy-launch-templatewith the name and version of the launch template that you created for instances registered to a VPC Lattice target group. For the1--traffic-sourcesoption, replace the sample ARN with the ARN of your VPC Lattice target group.aws autoscaling create-auto-scaling-group --auto-scaling-group-namemy-asg\ --launch-template LaunchTemplateName=my-launch-template,Version='1' \ --vpc-zone-identifier "subnet-5ea0c127,subnet-6194ea3b,subnet-c934b782" \ --min-size1--max-size5\ --traffic-sources "Identifier=arn:aws:vpc-lattice:region:account-id:targetgroup/tg-0e2f2665eEXAMPLE"Use the following attach-traffic-sources
command to attach a VPC Lattice target group to an Amazon EC2 Auto Scaling group after it's already created. aws autoscaling attach-traffic-sources --auto-scaling-group-namemy-asg\ --traffic-sources "Identifier=arn:aws:vpc-lattice:region:account-id:targetgroup/tg-0e2f2665eEXAMPLE"To turn on the health checks for VPC Lattice
If you have configured an application-based health check for your VPC Lattice target group, you can turn on these health checks. Use the create-auto-scaling-group
or update-auto-scaling-group command with the --health-check-typeoption and a value of. To specify the grace period for the health checks performed by your Amazon EC2 Auto Scaling group, include theVPC_LATTICE--health-check-grace-periodoption and provide its value in seconds.--health-check-type "VPC_LATTICE" --health-check-grace-period60 -
Detach a VPC Lattice target group
If you no longer need to use VPC Lattice, use the following procedure to detach the target group from your Amazon EC2 Auto Scaling group.
- Console
-
Follow the steps in this section to use the console to:
-
Detach a VPC Lattice target group from an Amazon EC2 Auto Scaling group
-
Turn off the health checks for VPC Lattice
To detach a VPC Lattice target group from an Amazon EC2 Auto Scaling group
Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/
, and choose Amazon EC2 Auto Scaling Groups from the navigation pane. -
Select the check box next to an existing group.
A split pane opens up in the bottom of the page.
-
On the Details tab, choose VPC Lattice integration options, Edit.
-
Under VPC Lattice integration options, choose the delete (X) icon next to the target group.
-
Choose Update.
When you finish detaching the target group, you can turn off the VPC Lattice health checks.
To turn off the VPC Lattice health checks
-
On the Details tab, choose Health checks, Edit.
-
For Health checks, Additional health check types, deselect Turn on VPC Lattice health checks.
-
Choose Update.
-
- AWS CLI
-
Follow the steps in this section to use the AWS CLI to:
-
Detach a VPC Lattice target group from an Amazon EC2 Auto Scaling group
-
Turn off the health checks for VPC Lattice
Use the detach-traffic-sources
command to detach a target group from your Amazon EC2 Auto Scaling group when you no longer need it. aws autoscaling detach-traffic-sources --auto-scaling-group-namemy-asg\ --traffic-sources "Identifier=arn:aws:vpc-lattice:region:account-id:targetgroup/tg-0e2f2665eEXAMPLE"To update the health checks on an Amazon EC2 Auto Scaling group so that it no longer uses VPC Lattice health checks, use the update-auto-scaling-group
command. Include the --health-check-typeoption and a value of.EC2aws autoscaling update-auto-scaling-group --auto-scaling-group-namemy-asg\ --health-check-type "EC2" -