Menu
AWS CloudFormation
User Guide (API Version 2010-05-15)

AWS::ElasticLoadBalancingV2::LoadBalancer

The AWS::ElasticLoadBalancingV2::LoadBalancer resource creates an Elastic Load Balancing Application or Network Load Balancer. For more information, see the 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

Copy
{ "Type" : "AWS::ElasticLoadBalancingV2::LoadBalancer", "Properties" : { "LoadBalancerAttributes" : [ LoadBalancerAttributes, ... ], "Name" : String, "Scheme" : String, "SecurityGroups" : [ String, ... ], "SubnetMappings" : [ SubnetMapping, ... ], "Subnets" : [ String, ... ], "Tags" : [ Resource Tag, ... ], "Type" : String, "IpAddressType" : String } }

YAML

Copy
Type: "AWS::ElasticLoadBalancingV2::LoadBalancer" Properties: LoadBalancerAttributes: - LoadBalancerAttributes Name: String Scheme: String SecurityGroups: - String SubnetMappings: - SubnetMapping Subnets: - String Tags: - Resource Tag Type: String IpAddressType: String

Properties

For more information and valid parameter values, see the see the CreateLoadBalancer action in the Elastic Load Balancing API Reference version 2015-12-01.

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.

Required: No

Type: String

Update requires: Replacement

Scheme

Specifies whether the load balancer is internal or Internet-facing. Valid values are internet-facing and internal. The default is internet-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 SubnetMapping property types. You can specify only one subnet per Availability Zone. You must specify either subnets or subnet mappings.

[Application Load Balancers] The load balancer is allocated one static IP address per subnet. You cannot specify your own Elastic IP addresses.

[Network Load Balancers] 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: AWS CloudFormation Resource Tags

Update requires: No interruption

Type

Specifies the type of load balancer to create. Valid values are application and network.The default is application.

Required: No

Type: String

Update requires: Replacement

IpAddressType

[Application Load Balancers] The type of IP addresses that are used by the load balancer's subnets, such as ipv4 (for IPv4 addresses) or dualstack (for IPv4 and IPv6 addresses). For valid values, see the IpAddressType parameter for the CreateLoadBalancer action in the Elastic Load Balancing API Reference version 2015-12-01.

Required: No

Type: String

Update requires: No interruption

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:

Copy
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.

DNSName

The DNS name for the load balancer, for example my-load-balancer-424835706.us-west-2.elb.amazonaws.com.

CanonicalHostedZoneID

The ID of the Amazon Route 53 hosted zone associated with the load balancer, for example Z2P70J7EXAMPLE.

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

Copy
"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

Copy
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

Copy
{ "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

Copy
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