- Navigation GuideYou are on a Command (operation) page with structural examples. Use the navigation breadcrumb if you would like to return to the Client landing page.
CreateLoadBalancerCommand
Creates an Application Load Balancer, Network Load Balancer, or Gateway Load Balancer.
For more information, see the following:
This operation is idempotent, which means that it completes at most one time. If you attempt to create multiple load balancers with the same settings, each call succeeds.
Example Syntax
Use a bare-bones client and the command you need to make an API call.
import { ElasticLoadBalancingV2Client, CreateLoadBalancerCommand } from "@aws-sdk/client-elastic-load-balancing-v2"; // ES Modules import
// const { ElasticLoadBalancingV2Client, CreateLoadBalancerCommand } = require("@aws-sdk/client-elastic-load-balancing-v2"); // CommonJS import
const client = new ElasticLoadBalancingV2Client(config);
const input = { // CreateLoadBalancerInput
Name: "STRING_VALUE", // required
Subnets: [ // Subnets
"STRING_VALUE",
],
SubnetMappings: [ // SubnetMappings
{ // SubnetMapping
SubnetId: "STRING_VALUE",
AllocationId: "STRING_VALUE",
PrivateIPv4Address: "STRING_VALUE",
IPv6Address: "STRING_VALUE",
SourceNatIpv6Prefix: "STRING_VALUE",
},
],
SecurityGroups: [ // SecurityGroups
"STRING_VALUE",
],
Scheme: "internet-facing" || "internal",
Tags: [ // TagList
{ // Tag
Key: "STRING_VALUE", // required
Value: "STRING_VALUE",
},
],
Type: "application" || "network" || "gateway",
IpAddressType: "ipv4" || "dualstack" || "dualstack-without-public-ipv4",
CustomerOwnedIpv4Pool: "STRING_VALUE",
EnablePrefixForIpv6SourceNat: "on" || "off",
IpamPools: { // IpamPools
Ipv4IpamPoolId: "STRING_VALUE",
},
};
const command = new CreateLoadBalancerCommand(input);
const response = await client.send(command);
// { // CreateLoadBalancerOutput
// LoadBalancers: [ // LoadBalancers
// { // LoadBalancer
// LoadBalancerArn: "STRING_VALUE",
// DNSName: "STRING_VALUE",
// CanonicalHostedZoneId: "STRING_VALUE",
// CreatedTime: new Date("TIMESTAMP"),
// LoadBalancerName: "STRING_VALUE",
// Scheme: "internet-facing" || "internal",
// VpcId: "STRING_VALUE",
// State: { // LoadBalancerState
// Code: "active" || "provisioning" || "active_impaired" || "failed",
// Reason: "STRING_VALUE",
// },
// Type: "application" || "network" || "gateway",
// AvailabilityZones: [ // AvailabilityZones
// { // AvailabilityZone
// ZoneName: "STRING_VALUE",
// SubnetId: "STRING_VALUE",
// OutpostId: "STRING_VALUE",
// LoadBalancerAddresses: [ // LoadBalancerAddresses
// { // LoadBalancerAddress
// IpAddress: "STRING_VALUE",
// AllocationId: "STRING_VALUE",
// PrivateIPv4Address: "STRING_VALUE",
// IPv6Address: "STRING_VALUE",
// },
// ],
// SourceNatIpv6Prefixes: [ // SourceNatIpv6Prefixes
// "STRING_VALUE",
// ],
// },
// ],
// SecurityGroups: [ // SecurityGroups
// "STRING_VALUE",
// ],
// IpAddressType: "ipv4" || "dualstack" || "dualstack-without-public-ipv4",
// CustomerOwnedIpv4Pool: "STRING_VALUE",
// EnforceSecurityGroupInboundRulesOnPrivateLinkTraffic: "STRING_VALUE",
// EnablePrefixForIpv6SourceNat: "on" || "off",
// IpamPools: { // IpamPools
// Ipv4IpamPoolId: "STRING_VALUE",
// },
// },
// ],
// };
Example Usage
CreateLoadBalancerCommand Input
Parameter | Type | Description |
---|
Parameter | Type | Description |
---|---|---|
Name Required | string | undefined | The name of the load balancer. This name must be unique per region per account, can have a maximum of 32 characters, must contain only alphanumeric characters or hyphens, must not begin or end with a hyphen, and must not begin with "internal-". |
CustomerOwnedIpv4Pool | string | undefined | [Application Load Balancers on Outposts] The ID of the customer-owned address pool (CoIP pool). |
EnablePrefixForIpv6SourceNat | EnablePrefixForIpv6SourceNatEnum | undefined | [Network Load Balancers with UDP listeners] Indicates whether to use an IPv6 prefix from each subnet for source NAT. The IP address type must be |
IpAddressType | IpAddressType | undefined | The IP address type. Internal load balancers must use [Application Load Balancers] The possible values are [Network Load Balancers and Gateway Load Balancers] The possible values are |
IpamPools | IpamPools | undefined | [Application Load Balancers] The IPAM pools to use with the load balancer. |
Scheme | LoadBalancerSchemeEnum | undefined | 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 route requests only from clients with access to the VPC for the load balancer. The default is an Internet-facing load balancer. You can't specify a scheme for a Gateway Load Balancer. |
SecurityGroups | string[] | undefined | [Application Load Balancers and Network Load Balancers] The IDs of the security groups for the load balancer. |
SubnetMappings | SubnetMapping[] | undefined | The IDs of the subnets. You can specify only one subnet per Availability Zone. You must specify either subnets or subnet mappings, but not both. [Application Load Balancers] You must specify subnets from at least two Availability Zones. You can't specify Elastic IP addresses for your subnets. [Application Load Balancers on Outposts] You must specify one Outpost subnet. [Application Load Balancers on Local Zones] You can specify subnets from one or more Local Zones. [Network Load Balancers] You can specify subnets from one or more Availability Zones. You can specify one Elastic IP address per subnet if you need static IP addresses for your internet-facing load balancer. For internal load balancers, you can specify one private IP address per subnet from the IPv4 range of the subnet. For internet-facing load balancer, you can specify one IPv6 address per subnet. [Gateway Load Balancers] You can specify subnets from one or more Availability Zones. You can't specify Elastic IP addresses for your subnets. |
Subnets | string[] | undefined | The IDs of the subnets. You can specify only one subnet per Availability Zone. You must specify either subnets or subnet mappings, but not both. To specify an Elastic IP address, specify subnet mappings instead of subnets. [Application Load Balancers] You must specify subnets from at least two Availability Zones. [Application Load Balancers on Outposts] You must specify one Outpost subnet. [Application Load Balancers on Local Zones] You can specify subnets from one or more Local Zones. [Network Load Balancers and Gateway Load Balancers] You can specify subnets from one or more Availability Zones. |
Tags | Tag[] | undefined | The tags to assign to the load balancer. |
Type | LoadBalancerTypeEnum | undefined | The type of load balancer. The default is |
CreateLoadBalancerCommand Output
Parameter | Type | Description |
---|
Parameter | Type | Description |
---|---|---|
$metadata Required | ResponseMetadata | Metadata pertaining to this request. |
LoadBalancers | LoadBalancer[] | undefined | Information about the load balancer. |
Throws
Name | Fault | Details |
---|
Name | Fault | Details |
---|---|---|
AllocationIdNotFoundException | client | The specified allocation ID does not exist. |
AvailabilityZoneNotSupportedException | client | The specified Availability Zone is not supported. |
DuplicateLoadBalancerNameException | client | A load balancer with the specified name already exists. |
DuplicateTagKeysException | client | A tag key was specified more than once. |
InvalidConfigurationRequestException | client | The requested configuration is not valid. |
InvalidSchemeException | client | The requested scheme is not valid. |
InvalidSecurityGroupException | client | The specified security group does not exist. |
InvalidSubnetException | client | The specified subnet is out of available addresses. |
OperationNotPermittedException | client | This operation is not allowed. |
ResourceInUseException | client | A specified resource is in use. |
SubnetNotFoundException | client | The specified subnet does not exist. |
TooManyLoadBalancersException | client | You've reached the limit on the number of load balancers for your Amazon Web Services account. |
TooManyTagsException | client | You've reached the limit on the number of tags for this resource. |
ElasticLoadBalancingV2ServiceException | Base exception class for all service exceptions from ElasticLoadBalancingV2 service. |