AWS::ElasticLoadBalancingV2::LoadBalancer
The AWS::ElasticLoadBalancingV2::LoadBalancer resource creates an Elastic Load Balancing
Application or Network Load Balancer. For more information, see Getting Started in the Elastic Load Balancing User Guide.
Note
AWS CloudFormation does not automatically create tags (key–value pairs) for an Elastic Load Balancing load balancer. You must use the Tags property to create tags to associate with the load balancer.
Syntax
To declare this entity in your AWS CloudFormation template, use the following syntax:
JSON
{ "Type" : "AWS::ElasticLoadBalancingV2::LoadBalancer", "Properties" : { "IpAddressType" :String, "LoadBalancerAttributes" : [ LoadBalancerAttributes, ... ], "Name" :String, "Scheme" :String, "SecurityGroups" : [String, ...], "SubnetMappings" : [ SubnetMapping, ... ], "Subnets" : [String, ...], "Tags" : [Resource Tag, ...], "Type" :String} }
YAML
Type: AWS::ElasticLoadBalancingV2::LoadBalancer Properties: IpAddressType:StringLoadBalancerAttributes: -LoadBalancerAttributesName:StringScheme:StringSecurityGroups: -StringSubnetMappings: - SubnetMapping Subnets: -StringTags: -Resource TagType:String
Properties
For more information and valid parameter values, see the CreateLoadBalancer action
in the Elastic Load Balancing API Reference version 2015-12-01.
IpAddressType-
[Application Load Balancers] The type of IP addresses that are used by the load balancer's subnets, such as
ipv4(for IPv4 addresses) ordualstack(for IPv4 and IPv6 addresses). For valid values, see theIpAddressTypeparameter for theCreateLoadBalanceraction in the Elastic Load Balancing API Reference version 2015-12-01. The default value isipv4.Required: No
Type: String
Update requires: No interruption
Note
If
Schemeisinternal, thenIpAddressTypemust beipv4. LoadBalancerAttributes-
Specifies the load balancer configuration.
Required: No
Type: A list of Elastic Load Balancing LoadBalancer LoadBalancerAttributes
Update requires: No interruption
Name-
Specifies a name for the load balancer. This name must be unique within your AWS account and can have a maximum of 32 alphanumeric characters and hyphens. A name can't begin or end with a hyphen.
Important
If you specify a name, you cannot perform updates that require replacement of this resource. You can perform updates that require no or some interruption. If you must replace the resource, specify a new name.
Required: No
Type: String
Update requires: Replacement
Scheme-
Specifies whether the load balancer is internal or Internet-facing. Valid values are
internet-facingandinternal. The default isinternet-facing.The nodes of an Internet-facing load balancer have public IP addresses. The DNS name of an Internet-facing load balancer is publicly resolvable to the public IP addresses of the nodes. Therefore, Internet-facing load balancers can route requests from clients over the Internet.
The nodes of an internal load balancer have only private IP addresses. The DNS name of an internal load balancer is publicly resolvable to the private IP addresses of the nodes. Therefore, internal load balancers can only route requests from clients with access to the VPC for the load balancer.
Required: No
Type: String
Update requires: Replacement
SecurityGroups-
[Application Load Balancers] Specifies a list of the IDs of the security groups to assign to the load balancer.
Required: No
Type: List of String values
Update requires: No interruption
SubnetMappings-
The subnets to attach to the load balancer, specified as a list of
SubnetMappingproperty types. You can specify only one subnet per Availability Zone. You must specify either subnets or subnet mappings.[Application Load Balancers] You must specify subnets from at least two Availability Zones. You cannot specify your own Elastic IP addresses.
[Network Load Balancers] You can specify subnets from one or more Availability Zones. You can specify one Elastic IP address per subnet.
Required: No
Type: List of Elastic Load Balancing LoadBalancer SubnetMapping
Update requires: Replacement
Subnets-
The subnets to attach to the load balancer, specified as a list of subnet IDs. You can specify only one subnet per Availability Zone. You must specify either subnets or subnet mappings.
[Application Load Balancers] You must specify subnets from at least two Availability Zones.
Required: No
Type: List of String values
Update requires: No interruption
Tags-
Specifies an arbitrary set of tags (key–value pairs) to associate with this load balancer. Use tags to manage your resources.
Required: No
Type: Resource Tag
Update requires: No interruption
Type-
Specifies the type of load balancer to create. Valid values are
applicationandnetwork.The default isapplication.Required: No
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 ARN of the load balancer, for
example:
arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/app/my-internal-load-balancer/50dc6c495c0c9188
For more information about using the Ref function, see Ref.
Fn::GetAtt
Fn::GetAtt returns a value for the following attributes.
CanonicalHostedZoneID-
The ID of the Amazon Route 53 hosted zone associated with the load balancer, for example
Z2P70J7EXAMPLE. DNSName-
The DNS name for the load balancer, for example
my-load-balancer-424835706.us-west-2.elb.amazonaws.com. LoadBalancerFullName-
The full name of the load balancer, for example
app/my-load-balancer/50dc6c495c0c9188. LoadBalancerName-
The name of the load balancer, for example
my-load-balancer. SecurityGroups-
The IDs of the security groups for the load balancer, for example
sg-123456a.
For more information about using Fn::GetAtt, see Fn::GetAtt.
Examples
Load balancer with idle timeout period specified
The following example creates an internal load balancer with an idle timeout period
of 50 seconds.
JSON
"loadBalancer" : { "Type": "AWS::ElasticLoadBalancingV2::LoadBalancer", "Properties": { "Scheme" : "internal", "Subnets" : [ {"Ref": "SubnetAZ1"}, {"Ref" : "SubnetAZ2"}], "LoadBalancerAttributes" : [ { "Key" : "idle_timeout.timeout_seconds", "Value" : "50" } ], "SecurityGroups": [{"Ref": "SecurityGroup1"}, {"Ref" : "SecurityGroup2"}], "Tags" : [ { "Key" : "key", "Value" : "value" }, { "Key" : "key2", "Value" : "value2" } ] } }
YAML
loadBalancer: Type: AWS::ElasticLoadBalancingV2::LoadBalancer Properties: Scheme: internal Subnets: - Ref: SubnetAZ1 - Ref: SubnetAZ2 LoadBalancerAttributes: - Key: idle_timeout.timeout_seconds Value: '50' SecurityGroups: - Ref: SecurityGroup1 - Ref: SecurityGroup2 Tags: - Key: key Value: value - Key: key2 Value: value2
Load balancer with subnets
The following example creates a load balancer with two mapped subnets.
JSON
{ "Parameters": { "FirstSubnet": { "Type": "String" }, "SecondSubnet": { "Type": "String" }, "ELBType": { "Type": "String" }, "ELBIpAddressType": { "Type": "String" } }, "Resources": { "loadBalancer": { "Type": "AWS::ElasticLoadBalancingV2::LoadBalancer", "Properties": { "SubnetMappings": [ { "AllocationId": { "Fn::GetAtt": [ "FirstEIP", "AllocationId" ] }, "SubnetId": { "Ref": "FirstSubnet" } }, { "AllocationId": { "Fn::GetAtt": [ "SecondEIP", "AllocationId" ] }, "SubnetId": { "Ref": "SecondSubnet" } } ], "Type": { "Ref": "ELBType" }, "IpAddressType": { "Ref": "ELBIpAddressType" } } }, "FirstEIP": { "Type": "AWS::EC2::EIP", "Properties": { "Domain": "vpc" } }, "SecondEIP": { "Type": "AWS::EC2::EIP", "Properties": { "Domain": "vpc" } } } }
YAML
Parameters: FirstSubnet: Type: String SecondSubnet: Type: String ELBType: Type: String ELBIpAddressType: Type: String Resources: loadBalancer: Type: AWS::ElasticLoadBalancingV2::LoadBalancer Properties: SubnetMappings: - AllocationId: !GetAtt - FirstEIP - AllocationId SubnetId: !Ref FirstSubnet - AllocationId: !GetAtt - SecondEIP - AllocationId SubnetId: !Ref SecondSubnet Type: !Ref ELBType IpAddressType: !Ref ELBIpAddressType FirstEIP: Type: AWS::EC2::EIP Properties: Domain: vpc SecondEIP: Type: AWS::EC2::EIP Properties: Domain: vpc
