LoadBalancer class
Provides a Load Balancer resource.
> Note: aws.alb.LoadBalancer is known as aws.lb.LoadBalancer. The functionality is identical.
Example Usage
Application Load Balancer
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
const test = new aws.lb.LoadBalancer("test", {
accessLogs: {
bucket: lbLogs.id,
prefix: "test-lb",
enabled: true,
},
name: "test-lb-tf",
internal: false,
loadBalancerType: "application",
securityGroups: [lbSg.id],
subnets: .map(subnet => (subnet.id)),
enableDeletionProtection: true,
tags: {
Environment: "production",
},
});
import pulumi
import pulumi_aws as aws
test = aws.lb.LoadBalancer("test",
access_logs={
"bucket": lb_logs["id"],
"prefix": "test-lb",
"enabled": True,
},
name="test-lb-tf",
internal=False,
load_balancer_type="application",
security_groups=[lb_sg["id"]],
subnets=[subnet["id"] for subnet in public],
enable_deletion_protection=True,
tags={
"Environment": "production",
})
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;
return await Deployment.RunAsync(() =>
{
var test = new Aws.LB.LoadBalancer("test", new()
{
AccessLogs = new Aws.LB.Inputs.LoadBalancerAccessLogsArgs
{
Bucket = lbLogs.Id,
Prefix = "test-lb",
Enabled = true,
},
Name = "test-lb-tf",
Internal = false,
LoadBalancerType = "application",
SecurityGroups = new[]
{
lbSg.Id,
},
Subnets = .Select(subnet =>
{
return subnet.Id;
}).ToList(),
EnableDeletionProtection = true,
Tags =
{
{ "Environment", "production" },
},
});
});
pulumi {
required_providers {
aws = {
source = "pulumi/aws"
}
}
}
resource "aws_lb_loadbalancer" "test" {
access_logs = {
bucket = lbLogs.id
prefix = "test-lb"
enabled = true
}
name = "test-lb-tf"
internal = false
load_balancer_type = "application"
security_groups = [lbSg.id]
subnets = [for subnet in public : subnet.id]
enable_deletion_protection = true
tags = {
"Environment" = "production"
}
}
Network Load Balancer
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
const test = new aws.lb.LoadBalancer("test", {
name: "test-lb-tf",
internal: false,
loadBalancerType: "network",
subnets: .map(subnet => (subnet.id)),
enableDeletionProtection: true,
tags: {
Environment: "production",
},
});
import pulumi
import pulumi_aws as aws
test = aws.lb.LoadBalancer("test",
name="test-lb-tf",
internal=False,
load_balancer_type="network",
subnets=[subnet["id"] for subnet in public],
enable_deletion_protection=True,
tags={
"Environment": "production",
})
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;
return await Deployment.RunAsync(() =>
{
var test = new Aws.LB.LoadBalancer("test", new()
{
Name = "test-lb-tf",
Internal = false,
LoadBalancerType = "network",
Subnets = .Select(subnet =>
{
return subnet.Id;
}).ToList(),
EnableDeletionProtection = true,
Tags =
{
{ "Environment", "production" },
},
});
});
pulumi {
required_providers {
aws = {
source = "pulumi/aws"
}
}
}
resource "aws_lb_loadbalancer" "test" {
name = "test-lb-tf"
internal = false
load_balancer_type = "network"
subnets = [for subnet in public : subnet.id]
enable_deletion_protection = true
tags = {
"Environment" = "production"
}
}
Specifying Elastic IPs
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
const example = new aws.lb.LoadBalancer("example", {
subnetMappings: [
{
subnetId: example1.id,
allocationId: example1AwsEip.id,
},
{
subnetId: example2.id,
allocationId: example2AwsEip.id,
},
],
name: "example",
loadBalancerType: "network",
});
import pulumi
import pulumi_aws as aws
example = aws.lb.LoadBalancer("example",
subnet_mappings=[
{
"subnet_id": example1["id"],
"allocation_id": example1_aws_eip["id"],
},
{
"subnet_id": example2["id"],
"allocation_id": example2_aws_eip["id"],
},
],
name="example",
load_balancer_type="network")
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;
return await Deployment.RunAsync(() =>
{
var example = new Aws.LB.LoadBalancer("example", new()
{
SubnetMappings = new[]
{
new Aws.LB.Inputs.LoadBalancerSubnetMappingArgs
{
SubnetId = example1.Id,
AllocationId = example1AwsEip.Id,
},
new Aws.LB.Inputs.LoadBalancerSubnetMappingArgs
{
SubnetId = example2.Id,
AllocationId = example2AwsEip.Id,
},
},
Name = "example",
LoadBalancerType = "network",
});
});
package main
import (
"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/lb"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
_, err := lb.NewLoadBalancer(ctx, "example", &lb.LoadBalancerArgs{
SubnetMappings: lb.LoadBalancerSubnetMappingArray{
&lb.LoadBalancerSubnetMappingArgs{
SubnetId: pulumi.Any(example1.Id),
AllocationId: pulumi.Any(example1AwsEip.Id),
},
&lb.LoadBalancerSubnetMappingArgs{
SubnetId: pulumi.Any(example2.Id),
AllocationId: pulumi.Any(example2AwsEip.Id),
},
},
Name: pulumi.String("example"),
LoadBalancerType: pulumi.String("network"),
})
if err != nil {
return err
}
return nil
})
}
pulumi {
required_providers {
aws = {
source = "pulumi/aws"
}
}
}
resource "aws_lb_loadbalancer" "example" {
subnet_mappings {
subnet_id = example1.id
allocation_id = example1AwsEip.id
}
subnet_mappings {
subnet_id = example2.id
allocation_id = example2AwsEip.id
}
name = "example"
load_balancer_type = "network"
}
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.lb.LoadBalancer;
import com.pulumi.aws.lb.LoadBalancerArgs;
import com.pulumi.aws.lb.inputs.LoadBalancerSubnetMappingArgs;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
var example = new LoadBalancer("example", LoadBalancerArgs.builder()
.subnetMappings(
LoadBalancerSubnetMappingArgs.builder()
.subnetId(example1.id())
.allocationId(example1AwsEip.id())
.build(),
LoadBalancerSubnetMappingArgs.builder()
.subnetId(example2.id())
.allocationId(example2AwsEip.id())
.build())
.name("example")
.loadBalancerType("network")
.build());
}
}
resources:
example:
type: aws:lb:LoadBalancer
properties:
subnetMappings:
- subnetId: ${example1.id}
allocationId: ${example1AwsEip.id}
- subnetId: ${example2.id}
allocationId: ${example2AwsEip.id}
name: example
loadBalancerType: network
Specifying private IP addresses for an internal-facing load balancer
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
const example = new aws.lb.LoadBalancer("example", {
subnetMappings: [
{
subnetId: example1.id,
privateIpv4Address: "10.0.1.15",
},
{
subnetId: example2.id,
privateIpv4Address: "10.0.2.15",
},
],
name: "example",
loadBalancerType: "network",
});
import pulumi
import pulumi_aws as aws
example = aws.lb.LoadBalancer("example",
subnet_mappings=[
{
"subnet_id": example1["id"],
"private_ipv4_address": "10.0.1.15",
},
{
"subnet_id": example2["id"],
"private_ipv4_address": "10.0.2.15",
},
],
name="example",
load_balancer_type="network")
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;
return await Deployment.RunAsync(() =>
{
var example = new Aws.LB.LoadBalancer("example", new()
{
SubnetMappings = new[]
{
new Aws.LB.Inputs.LoadBalancerSubnetMappingArgs
{
SubnetId = example1.Id,
PrivateIpv4Address = "10.0.1.15",
},
new Aws.LB.Inputs.LoadBalancerSubnetMappingArgs
{
SubnetId = example2.Id,
PrivateIpv4Address = "10.0.2.15",
},
},
Name = "example",
LoadBalancerType = "network",
});
});
package main
import (
"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/lb"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
_, err := lb.NewLoadBalancer(ctx, "example", &lb.LoadBalancerArgs{
SubnetMappings: lb.LoadBalancerSubnetMappingArray{
&lb.LoadBalancerSubnetMappingArgs{
SubnetId: pulumi.Any(example1.Id),
PrivateIpv4Address: pulumi.String("10.0.1.15"),
},
&lb.LoadBalancerSubnetMappingArgs{
SubnetId: pulumi.Any(example2.Id),
PrivateIpv4Address: pulumi.String("10.0.2.15"),
},
},
Name: pulumi.String("example"),
LoadBalancerType: pulumi.String("network"),
})
if err != nil {
return err
}
return nil
})
}
pulumi {
required_providers {
aws = {
source = "pulumi/aws"
}
}
}
resource "aws_lb_loadbalancer" "example" {
subnet_mappings {
subnet_id = example1.id
private_ipv4_address = "10.0.1.15"
}
subnet_mappings {
subnet_id = example2.id
private_ipv4_address = "10.0.2.15"
}
name = "example"
load_balancer_type = "network"
}
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.lb.LoadBalancer;
import com.pulumi.aws.lb.LoadBalancerArgs;
import com.pulumi.aws.lb.inputs.LoadBalancerSubnetMappingArgs;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
var example = new LoadBalancer("example", LoadBalancerArgs.builder()
.subnetMappings(
LoadBalancerSubnetMappingArgs.builder()
.subnetId(example1.id())
.privateIpv4Address("10.0.1.15")
.build(),
LoadBalancerSubnetMappingArgs.builder()
.subnetId(example2.id())
.privateIpv4Address("10.0.2.15")
.build())
.name("example")
.loadBalancerType("network")
.build());
}
}
resources:
example:
type: aws:lb:LoadBalancer
properties:
subnetMappings:
- subnetId: ${example1.id}
privateIpv4Address: 10.0.1.15
- subnetId: ${example2.id}
privateIpv4Address: 10.0.2.15
name: example
loadBalancerType: network
Import
Identity Schema
Required
arn(String) ARN of the load balancer.
Using pulumi import, import LBs using their ARN. For example:
$ pulumi import aws:lb/loadBalancer:LoadBalancer bar arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/app/my-load-balancer/50dc6c495c0c9188
Constructors
- LoadBalancer(String name, {LoadBalancerArgs? args, CustomResourceOptions? options})
-
Creates a new LoadBalancer.
nameThe Pulumi resource name.argsArguments used to configure this LoadBalancer. The set of arguments for LoadBalancer.optionsResource options controlling this resource's behavior. - LoadBalancer.reference(String urn)
- Creates a typed reference to an existing LoadBalancer resource.
Properties
-
accessLogs
↔ Output<
LoadBalancerAccessLogs?> -
Access Logs block. See below.
latefinal
-
arn
↔ Output<
String> -
ARN of the load balancer.
latefinal
-
arnSuffix
↔ Output<
String> -
ARN suffix for use with CloudWatch Metrics.
latefinal
-
childResources
→ Set<
Resource> -
finalinherited
-
clientKeepAlive
↔ Output<
int?> -
Client keep alive value in seconds. The valid range is 60-604800 seconds. The default is 3600 seconds.
latefinal
-
completionSources
↔ Map<
String, IOutputCompletionSource> -
latefinalinherited
-
connectionLogs
↔ Output<
LoadBalancerConnectionLogs?> -
Connection Logs block. See below. Only valid for Load Balancers of type
application.latefinal -
customerOwnedIpv4Pool
↔ Output<
String?> -
ID of the customer owned ipv4 pool to use for this load balancer.
latefinal
-
desyncMitigationMode
↔ Output<
String?> -
How the load balancer handles requests that might pose a security risk to an application due to HTTP desync. Valid values are
monitor,defensive(default),strictest.latefinal -
dnsName
↔ Output<
String> -
DNS name of the load balancer.
latefinal
-
dnsRecordClientRoutingPolicy
↔ Output<
String?> -
How traffic is distributed among the load balancer Availability Zones. Possible values are
anyAvailabilityZone(default),availabilityZoneAffinity, orpartialAvailabilityZoneAffinity. See Availability Zone DNS affinity for additional details. Only valid fornetworktype load balancers.latefinal -
dropInvalidHeaderFields
↔ Output<
bool?> -
Whether HTTP headers with header fields that are not valid are removed by the load balancer (true) or routed to targets (false). The default is false. Elastic Load Balancing requires that message header names contain only alphanumeric characters and hyphens. Only valid for Load Balancers of type
application.latefinal -
enableCrossZoneLoadBalancing
↔ Output<
bool?> -
If true, cross-zone load balancing of the load balancer will be enabled. For
networkandgatewaytype load balancers, this feature is disabled by default (false). Forapplicationload balancer this feature is always enabled (true) and cannot be disabled. Defaults tofalse.latefinal -
enableDeletionProtection
↔ Output<
bool?> -
If true, deletion of the load balancer will be disabled via the AWS API. This will prevent this provider from deleting the load balancer. Defaults to
false.latefinal -
enableHttp2
↔ Output<
bool?> -
Whether HTTP/2 is enabled in
applicationload balancers. Defaults totrue.latefinal -
enablePrefixForIpv6SourceNat
↔ Output<
String> -
Whether to use an IPv6 prefix from each subnet for source NAT.
ipAddressTypemust bedualstack. Valid values:on,off.latefinal -
enableTlsVersionAndCipherSuiteHeaders
↔ Output<
bool?> -
Whether the two headers (
x-amzn-tls-versionandx-amzn-tls-cipher-suite), which contain information about the negotiated TLS version and cipher suite, are added to the client request before sending it to the target. Only valid for Load Balancers of typeapplication. Defaults tofalselatefinal -
enableWafFailOpen
↔ Output<
bool?> -
Whether to allow a WAF-enabled load balancer to route requests to targets if it is unable to forward the request to AWS WAF. Defaults to
false.latefinal -
enableXffClientPort
↔ Output<
bool?> -
Whether the X-Forwarded-For header should preserve the source port that the client used to connect to the load balancer in
applicationload balancers. Defaults tofalse.latefinal -
enableZonalShift
↔ Output<
bool?> -
Whether zonal shift is enabled. Defaults to
false.latefinal -
enforceSecurityGroupInboundRulesOnPrivateLinkTraffic
↔ Output<
String> -
Whether inbound security group rules are enforced for traffic originating from a PrivateLink. Only valid for Load Balancers of type
network. The possible values areonandoff.latefinal - hashCode → int
-
The hash code for this object.
no setterinherited
-
healthCheckLogs
↔ Output<
LoadBalancerHealthCheckLogs?> -
Health Check Logs block. See below. Only valid for Load Balancers of type
application.latefinal -
id
↔ Output<
String> -
getter/setter pairinherited
-
idleTimeout
↔ Output<
int?> -
Time in seconds that the connection is allowed to be idle. Only valid for Load Balancers of type
application. Default: 60.latefinal -
internal
↔ Output<
bool> -
If true, the LB will be internal. Defaults to
false.latefinal -
ipAddressType
↔ Output<
String> -
Type of IP addresses used by the subnets for your load balancer. The possible values depend upon the load balancer type:
ipv4(all load balancer types),dualstack(all load balancer types), anddualstack-without-public-ipv4(typeapplicationonly).latefinal -
ipamPools
↔ Output<
LoadBalancerIpamPools?> -
. The IPAM pools to use with the load balancer. Only valid for Load Balancers of type
application. See ipamPools for more information.latefinal - isCustom → bool
-
Returns whether this resource is provider-managed.
no setterinherited
- isProtected → bool
-
Returns whether this resource is protected from deletion.
no setterinherited
- isRemote → bool
-
Whether this resource is registered as remote.
no setterinherited
- isResourceReference → bool
-
Whether this instance represents a resource value returned over RPC.
finalinherited
-
loadBalancerType
↔ Output<
String?> -
Type of load balancer to create. Possible values are
application,gateway, ornetwork. The default value isapplication.latefinal -
minimumLoadBalancerCapacity
↔ Output<
LoadBalancerMinimumLoadBalancerCapacity?> -
Minimum capacity for a load balancer. Only valid for Load Balancers of type
applicationornetwork.latefinal -
name
↔ Output<
String> -
Name of the LB. This name must be unique within your AWS account, can have a maximum of 32 characters, must contain only alphanumeric characters or hyphens, and must not begin or end with a hyphen. If not specified, this provider will autogenerate a name beginning with
tf-lb.latefinal -
namePrefix
↔ Output<
String> -
Creates a unique name beginning with the specified prefix. Conflicts with
name.latefinal -
preserveHostHeader
↔ Output<
bool?> -
Whether the Application Load Balancer should preserve the Host header in the HTTP request and send it to the target without any change. Defaults to
false.latefinal -
region
↔ Output<
String> -
Region where this resource will be managed. Defaults to the Region set in the provider configuration.
latefinal
-
resourceTransforms
→ List<
ResourceTransform> -
Inherited/explicit async transforms.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
secondaryIpsAutoAssignedPerSubnet
↔ Output<
int> -
The number of secondary IP addresses to configure for your load balancer nodes. Only valid for Load Balancers of type
network. The valid range is 0-7. When decreased, this will force a recreation of the resource. Default:0.latefinal -
securityGroups
↔ Output<
List< String> > -
List of security group IDs to assign to the LB. Only valid for Load Balancers of type
applicationornetwork. For load balancers of typenetworksecurity groups cannot be added if none are currently present, and cannot all be removed once added. If either of these conditions are met, this will force a recreation of the resource.latefinal -
subnetMappings
↔ Output<
List< LoadBalancerSubnetMapping> > -
Subnet mapping block. See below. For Load Balancers of type
networksubnet mappings can only be added.latefinal -
subnets
↔ Output<
List< String> > -
List of subnet IDs to attach to the LB. For Load Balancers of type
networksubnets can only be added (see Availability Zones), deleting a subnet for load balancers of typenetworkwill force a recreation of the resource.latefinal -
Map of tags to assign to the resource. If configured with a provider
defaultTagsconfiguration block present, tags with matching keys will overwrite those defined at the provider-level.latefinal -
Map of tags assigned to the resource, including those inherited from the provider
defaultTagsconfiguration block.latefinal -
transformations
→ List<
ResourceTransformation> -
Inherited/explicit legacy transformations.
no setterinherited
-
urn
↔ Output<
String> -
latefinalinherited
-
vpcId
↔ Output<
String> -
latefinal
-
xffHeaderProcessingMode
↔ Output<
String?> -
Determines how the load balancer modifies the
X-Forwarded-Forheader in the HTTP request before sending the request to the target. The possible values areappend,preserve, andremove. Only valid for Load Balancers of typeapplication. The default isappend.latefinal -
zoneId
↔ Output<
String> -
Canonical hosted zone ID of the load balancer (to be used in a Route 53 Alias record).
latefinal
Methods
-
failId(
Object error) → void -
Completes this resource ID with an error when registration fails.
inherited
-
failOutputs(
Object error) → void -
Completes all output properties with
error.inherited -
failUrn(
Object error) → void -
Completes this resource URN with an error when registration fails.
inherited
-
getProvider(
String moduleMember) → ProviderResource? -
Returns provider for
moduleMember's package, if configured.inherited -
getResourceName(
) → String -
Returns this resource's logical name.
inherited
-
getResourceType(
) → String -
Returns this resource's Pulumi type token.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
registerOutput<
T> (String propertyName, {Object? decoder(Object?)?, bool isSecret = false}) → Output< T> -
Registers a dynamic output property for this resource.
inherited
-
resolveId(
String? value, {required bool isKnown}) → void -
Resolves the provider-assigned ID for this resource.
inherited
-
resolveOutputs(
Struct outputs) → void -
Resolves all output properties from a monitor response payload.
inherited
-
resolveUrn(
String value) → void -
Resolves this resource's URN once assigned by the engine.
inherited
-
serializeProperties(
Map< String, dynamic> properties) → Future<Struct> -
Serializes resource properties for RPC transmission.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
get(
String name, Input< String> id, {LoadBalancerState? state, CustomResourceOptions? options}) → LoadBalancer -
Gets an existing LoadBalancer resource's state with the given
nameandid.