AWS::ElasticLoadBalancingV2::TargetGroup
The AWS::ElasticLoadBalancingV2::TargetGroup resource creates an Elastic Load Balancing
target group that routes requests to one or more registered targets, such as EC2 instances.
For
more information, see Getting Started in the Elastic Load Balancing User Guide.
Syntax
To declare this entity in your AWS CloudFormation template, use the following syntax:
JSON
{ "Type" : "AWS::ElasticLoadBalancingV2::TargetGroup", "Properties" : { "HealthCheckIntervalSeconds" :Integer, "HealthCheckPath" :String, "HealthCheckPort" :String, "HealthCheckProtocol" :String, "HealthCheckTimeoutSeconds" :Integer, "HealthyThresholdCount" :Integer, "Matcher" :Matcher, "Name" :String, "Port" :Integer, "Protocol" :String, "Tags" : [Resource Tag, ...], "TargetGroupAttributes" : [TargetGroupAttributes, ...], "Targets" : [TargetDescription, ...], "TargetType" :String, "UnhealthyThresholdCount" :Integer, "VpcId" :String} }
YAML
Type: AWS::ElasticLoadBalancingV2::TargetGroup Properties: HealthCheckIntervalSeconds:IntegerHealthCheckPath:StringHealthCheckPort:StringHealthCheckProtocol:StringHealthCheckTimeoutSeconds:IntegerHealthyThresholdCount:IntegerMatcher:MatcherName:StringPort:IntegerProtocol:StringTags: -Resource TagTargetGroupAttributes: -TargetGroupAttributesTargets: -TargetDescriptionTargetType:StringUnhealthyThresholdCount:IntegerVpcId:String
Properties
HealthCheckIntervalSeconds-
The approximate number of seconds between health checks for an individual target.
For valid and default values, see the
HealthCheckIntervalSecondsparameter for the CreateTargetGroup action in the .Required: No
Type: Integer
Update requires: No interruption
HealthCheckPath-
[HTTP/HTTPS health checks] The ping path destination where Elastic Load Balancing sends health check requests. The default is
/.Required: No
Type: String
Update requires: No interruption
HealthCheckPort-
The port that the load balancer uses when performing health checks on the targets.
For valid and default values, see the
HealthCheckPortparameter for the CreateTargetGroup action in the Elastic Load Balancing API Reference version 2015-12-01.Required: No
Type: String
Update requires: No interruption
HealthCheckProtocol-
The protocol that the load balancer uses when performing health checks on the targets, such as
HTTPorHTTPS.For valid and default values, see the
HealthCheckProtocolparameter for the CreateTargetGroup action in the Elastic Load Balancing API Reference version 2015-12-01.Required: No
Type: String
Update requires: No interruption
HealthCheckTimeoutSeconds-
The number of seconds to wait for a response before considering that a health check has failed. For Application Load Balancers, the range is 2–60 seconds and the default is 5 seconds. For Network Load Balancers, this value is 10 seconds for TCP and HTTPS health checks and 6 seconds for HTTP health checks.
Required: No
Type: Integer
Update requires: No interruption
HealthyThresholdCount-
The number of consecutive successful health checks that are required before an unhealthy target is considered healthy.
Required: No
Type: Integer
Update requires: No interruption
Matcher-
[HTTP/HTTPS health checks] The HTTP codes that a healthy target uses when responding to a health check.
For more information about specifying this property, see Matcher in the Elastic Load Balancing API Reference version 2015-12-01.
Required: No
Type: Elastic Load Balancing TargetGroup Matcher
Update requires: No interruption
Name-
A name for the target group.
Important
This name must be unique per account, per region.
The target group name should be shorter than 32 characters because AWS CloudFormation uses the target group name to create the name of the load balancer.
Required: No
Type: String
Update requires: Replacement
Port-
The port on which the targets receive traffic.
Required: Yes
Type: Integer
Update requires: Replacement
Protocol-
The protocol to use for routing traffic to the targets.
Required: Yes
Type: String
Update requires: Replacement
Tags-
An arbitrary set of tags (key–value pairs) for the target group. Use tags to help manage resources.
Required: No
Type: Resource Tag
Update requires: No interruption.
TargetGroupAttributes-
Target group configurations.
Required: No
Type: List of Elastic Load Balancing TargetGroup TargetGroupAttributes
Update requires: No interruption
Targets-
The targets to add to this target group.
Required: No
Type: List of Elastic Load Balancing TargetGroup TargetDescription
Update requires: No interruption
TargetType-
The registration type of the targets in this target group. Valid values are
instanceandip. The default isinstance.Required: No
Type: String
Update requires: Replacement
UnhealthyThresholdCount-
The number of consecutive failed health checks that are required before a target is considered unhealthy.
Required: No
Type: Integer
Update requires: No interruption
VpcId-
The ID of the VPC in which your targets are located.
Required: Yes
Type: String
Update requires: Replacement
Return Values
Ref
When the logical ID of this resource is provided to the Ref intrinsic function, Ref returns the target group's Amazon Resource Name (ARN), such as arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067.
For more information about using the Ref function, see Ref.
Fn::GetAtt
Fn::GetAtt returns a value for a specified attribute of this type.
The following are the available attributes and sample return values.
LoadBalancerArns-
A list of Amazon Resource Names (ARNs) of the load balancers that route traffic to this target group, such as
[ "arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/app/my-load-balancer/50dc6c495c0c9188" ]. TargetGroupFullName-
The full name of the target group, such as
targetgroup/my-target-group/cbf133c568e0d028. TargetGroupName-
The name of the target group, such as
my-target-group. This is the value of the target group'sNameproperty.
For more information about using Fn::GetAtt, see Fn::GetAtt.
Examples
Create a Target Group with EC2 Instances as Targets
The following examples creates a target group that includes the Instance1 and Instance2 EC2 instances as targets. The instances must respond with a 200 status code to pass health check requests.
JSON
"TargetGroup" : { "Type" : "AWS::ElasticLoadBalancingV2::TargetGroup", "Properties" : { "HealthCheckIntervalSeconds": 30, "HealthCheckProtocol": "HTTPS", "HealthCheckTimeoutSeconds": 10, "HealthyThresholdCount": 4, "Matcher" : { "HttpCode" : "200" }, "Name": "MyTargets", "Port": 10, "Protocol": "HTTPS", "TargetGroupAttributes": [{ "Key": "deregistration_delay.timeout_seconds", "Value": "20" }], "Targets": [ { "Id": {"Ref" : "Instance1"}, "Port": 80 }, { "Id": {"Ref" : "Instance2"}, "Port": 80 } ], "UnhealthyThresholdCount": 3, "VpcId": {"Ref" : "VPC"}, "Tags" : [ { "Key" : "key", "Value" : "value" }, { "Key" : "key2", "Value" : "value2" } ] } }
YAML
TargetGroup: Type: AWS::ElasticLoadBalancingV2::TargetGroup Properties: HealthCheckIntervalSeconds: 30 HealthCheckProtocol: HTTPS HealthCheckTimeoutSeconds: 10 HealthyThresholdCount: 4 Matcher: HttpCode: '200' Name: MyTargets Port: 10 Protocol: HTTPS TargetGroupAttributes: - Key: deregistration_delay.timeout_seconds Value: '20' Targets: - Id: Ref: Instance1 Port: 80 - Id: Ref: Instance2 Port: 80 UnhealthyThresholdCount: 3 VpcId: Ref: VPC Tags: - Key: key Value: value - Key: key2 Value: value2
Relate an Elastic Load Balancing Load Balancer to an Elastic Load Balancing Target Group
The following example creates an Elastic Load Balancing listener, associates it with a target group and a load balancer, and sets a target group attribute.
JSON
"ALBListener" : { "Type" : "AWS::ElasticLoadBalancingV2::Listener", "Properties" : { "DefaultActions" : [{ "Type" : "forward", "TargetGroupArn" : { "Ref" : "ALBTargetGroup" } }], "LoadBalancerArn" : { "Ref" : "ApplicationLoadBalancer" }, "Port" : "80", "Protocol" : "HTTP" } }, "ApplicationLoadBalancer" : { "Type" : "AWS::ElasticLoadBalancingV2::LoadBalancer", "Properties" : { "Scheme" : "internet-facing", "Subnets" : [ {"Ref" : "PublicSubnetAz1"}, {"Ref" : "PublicSubnetAz2"}], "SecurityGroups" : [{"Ref": "ALBSecurityGroup"}] } }, "ALBTargetGroup" : { "Type" : "AWS::ElasticLoadBalancingV2::TargetGroup", "Properties" : { "HealthCheckIntervalSeconds" : 60, "UnhealthyThresholdCount" : 10, "HealthCheckPath" : "/", "Name" : "MyTargetGroup", "Port" : 80, "Protocol" : "HTTP", "VpcId" : { "Ref": "MyVpc" } "TargetGroupAttributes" : [ { "Key" : deregistration_delay.timeout_seconds, "Value" : 60 } ] } }
YAML
ALBListener: Type: AWS::ElasticLoadBalancingV2::Listener Properties: DefaultActions: - Type: forward TargetGroupArn: Ref: ALBTargetGroup LoadBalancerArn: Ref: ApplicationLoadBalancer Port: 80 Protocol: HTTP ApplicationLoadBalancer: Type: AWS::ElasticLoadBalancingV2::LoadBalancer Properties: Scheme: internet-facing Subnets: Ref: PublicSubnetAz1 Ref: PublicSubnetAz2 SecurityGroups: Ref: ALBSecurityGroup ALBTargetGroup: Type: AWS::ElasticLoadBalancingV2::TargetGroup Properties: HealthCheckIntervalSeconds: 60 UnhealthyThresholdCount: 10 HealthCheckPath: / Name: MyTargetGroup Port: 80 Protocol: HTTP VpcId: Ref: MyVpc TargetGroupAttributes: - Key: deregistration_delay.timeout_seconds Value: 60
Specify the Elastic Load Balancing Target Group type
The following example specifies the target group type as instance.
JSON
{ "Parameters": { "CidrBlockForVPC": { "Type": "String" } }, "Resources": { "VPC": { "Type": "AWS::EC2::VPC", "Properties": { "CidrBlock": { "Ref": "CidrBlockForVPC" } } }, "TargetGroup": { "Type": "AWS::ElasticLoadBalancingV2::TargetGroup", "Properties": { "Port": 1000, "Protocol": "HTTPS", "TargetType": "instance", "VpcId": { "Ref": "VPC" } } } } }
YAML
Parameters: CidrBlockForVPC: Type: String Resources: VPC: Type: AWS::EC2::VPC Properties: CidrBlock: !Ref CidrBlockForVPC TargetGroup: Type: AWS::ElasticLoadBalancingV2::TargetGroup Properties: Port: 1000 Protocol: HTTPS TargetType: instance VpcId: !Ref VPC
