LoadBalancer class

Provides an Elastic Load Balancer resource, also known as a "Classic Load Balancer" after the release of Application/Network Load Balancers.

> NOTE on ELB Instances and ELB Attachments: This provider currently provides both a standalone ELB Attachment resource (describing an instance attached to an ELB), and an ELB resource with instances defined in-line. At this time you cannot use an ELB with in-line instances in conjunction with a ELB Attachment resources. Doing so will cause a conflict and will overwrite attachments.

Example Usage

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

// Create a new load balancer
const bar = new aws.elb.LoadBalancer("bar", {
    accessLogs: {
        bucket: "foo",
        bucketPrefix: "bar",
        interval: 60,
    },
    healthCheck: {
        healthyThreshold: 2,
        unhealthyThreshold: 2,
        timeout: 3,
        target: "HTTP:8000/",
        interval: 30,
    },
    listeners: [
        {
            instancePort: 8000,
            instanceProtocol: "http",
            lbPort: 80,
            lbProtocol: "http",
        },
        {
            instancePort: 8000,
            instanceProtocol: "http",
            lbPort: 443,
            lbProtocol: "https",
            sslCertificateId: "arn:aws:iam::123456789012:server-certificate/certName",
        },
    ],
    name: "foobar-elb",
    availabilityZones: [
        "us-west-2a",
        "us-west-2b",
        "us-west-2c",
    ],
    instances: [foo.id],
    crossZoneLoadBalancing: true,
    idleTimeout: 400,
    connectionDraining: true,
    connectionDrainingTimeout: 400,
    tags: {
        Name: "foobar-elb",
    },
});
import pulumi
import pulumi_aws as aws

# Create a new load balancer
bar = aws.elb.LoadBalancer("bar",
    access_logs={
        "bucket": "foo",
        "bucket_prefix": "bar",
        "interval": 60,
    },
    health_check={
        "healthy_threshold": 2,
        "unhealthy_threshold": 2,
        "timeout": 3,
        "target": "HTTP:8000/",
        "interval": 30,
    },
    listeners=[
        {
            "instance_port": 8000,
            "instance_protocol": "http",
            "lb_port": 80,
            "lb_protocol": "http",
        },
        {
            "instance_port": 8000,
            "instance_protocol": "http",
            "lb_port": 443,
            "lb_protocol": "https",
            "ssl_certificate_id": "arn:aws:iam::123456789012:server-certificate/certName",
        },
    ],
    name="foobar-elb",
    availability_zones=[
        "us-west-2a",
        "us-west-2b",
        "us-west-2c",
    ],
    instances=[foo["id"]],
    cross_zone_load_balancing=True,
    idle_timeout=400,
    connection_draining=True,
    connection_draining_timeout=400,
    tags={
        "Name": "foobar-elb",
    })
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;

return await Deployment.RunAsync(() =>
{
    // Create a new load balancer
    var bar = new Aws.Elb.LoadBalancer("bar", new()
    {
        AccessLogs = new Aws.Elb.Inputs.LoadBalancerAccessLogsArgs
        {
            Bucket = "foo",
            BucketPrefix = "bar",
            Interval = 60,
        },
        HealthCheck = new Aws.Elb.Inputs.LoadBalancerHealthCheckArgs
        {
            HealthyThreshold = 2,
            UnhealthyThreshold = 2,
            Timeout = 3,
            Target = "HTTP:8000/",
            Interval = 30,
        },
        Listeners = new[]
        {
            new Aws.Elb.Inputs.LoadBalancerListenerArgs
            {
                InstancePort = 8000,
                InstanceProtocol = "http",
                LbPort = 80,
                LbProtocol = "http",
            },
            new Aws.Elb.Inputs.LoadBalancerListenerArgs
            {
                InstancePort = 8000,
                InstanceProtocol = "http",
                LbPort = 443,
                LbProtocol = "https",
                SslCertificateId = "arn:aws:iam::123456789012:server-certificate/certName",
            },
        },
        Name = "foobar-elb",
        AvailabilityZones = new[]
        {
            "us-west-2a",
            "us-west-2b",
            "us-west-2c",
        },
        Instances = new[]
        {
            foo.Id,
        },
        CrossZoneLoadBalancing = true,
        IdleTimeout = 400,
        ConnectionDraining = true,
        ConnectionDrainingTimeout = 400,
        Tags =
        {
            { "Name", "foobar-elb" },
        },
    });

});
package main

import (
	"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/elb"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		// Create a new load balancer
		_, err := elb.NewLoadBalancer(ctx, "bar", &elb.LoadBalancerArgs{
			AccessLogs: &elb.LoadBalancerAccessLogsArgs{
				Bucket:       pulumi.String("foo"),
				BucketPrefix: pulumi.String("bar"),
				Interval:     pulumi.Int(60),
			},
			HealthCheck: &elb.LoadBalancerHealthCheckArgs{
				HealthyThreshold:   pulumi.Int(2),
				UnhealthyThreshold: pulumi.Int(2),
				Timeout:            pulumi.Int(3),
				Target:             pulumi.String("HTTP:8000/"),
				Interval:           pulumi.Int(30),
			},
			Listeners: elb.LoadBalancerListenerArray{
				&elb.LoadBalancerListenerArgs{
					InstancePort:     pulumi.Int(8000),
					InstanceProtocol: pulumi.String("http"),
					LbPort:           pulumi.Int(80),
					LbProtocol:       pulumi.String("http"),
				},
				&elb.LoadBalancerListenerArgs{
					InstancePort:     pulumi.Int(8000),
					InstanceProtocol: pulumi.String("http"),
					LbPort:           pulumi.Int(443),
					LbProtocol:       pulumi.String("https"),
					SslCertificateId: pulumi.String("arn:aws:iam::123456789012:server-certificate/certName"),
				},
			},
			Name: pulumi.String("foobar-elb"),
			AvailabilityZones: pulumi.StringArray{
				pulumi.String("us-west-2a"),
				pulumi.String("us-west-2b"),
				pulumi.String("us-west-2c"),
			},
			Instances: pulumi.StringArray{
				foo.Id,
			},
			CrossZoneLoadBalancing:    pulumi.Bool(true),
			IdleTimeout:               pulumi.Int(400),
			ConnectionDraining:        pulumi.Bool(true),
			ConnectionDrainingTimeout: pulumi.Int(400),
			Tags: pulumi.StringMap{
				"Name": pulumi.String("foobar-elb"),
			},
		})
		if err != nil {
			return err
		}
		return nil
	})
}
pulumi {
  required_providers {
    aws = {
      source = "pulumi/aws"
    }
  }
}

# Create a new load balancer
resource "aws_elb_loadbalancer" "bar" {
  access_logs = {
    bucket        = "foo"
    bucket_prefix = "bar"
    interval      = 60
  }
  health_check = {
    healthy_threshold   = 2
    unhealthy_threshold = 2
    timeout             = 3
    target              = "HTTP:8000/"
    interval            = 30
  }
  listeners {
    instance_port     = 8000
    instance_protocol = "http"
    lb_port           = 80
    lb_protocol       = "http"
  }
  listeners {
    instance_port      = 8000
    instance_protocol  = "http"
    lb_port            = 443
    lb_protocol        = "https"
    ssl_certificate_id = "arn:aws:iam::123456789012:server-certificate/certName"
  }
  name                        = "foobar-elb"
  availability_zones          = ["us-west-2a", "us-west-2b", "us-west-2c"]
  instances                   = [foo.id]
  cross_zone_load_balancing   = true
  idle_timeout                = 400
  connection_draining         = true
  connection_draining_timeout = 400
  tags = {
    "Name" = "foobar-elb"
  }
}
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.elb.LoadBalancer;
import com.pulumi.aws.elb.LoadBalancerArgs;
import com.pulumi.aws.elb.inputs.LoadBalancerAccessLogsArgs;
import com.pulumi.aws.elb.inputs.LoadBalancerHealthCheckArgs;
import com.pulumi.aws.elb.inputs.LoadBalancerListenerArgs;
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) {
        // Create a new load balancer
        var bar = new LoadBalancer("bar", LoadBalancerArgs.builder()
            .accessLogs(LoadBalancerAccessLogsArgs.builder()
                .bucket("foo")
                .bucketPrefix("bar")
                .interval(60)
                .build())
            .healthCheck(LoadBalancerHealthCheckArgs.builder()
                .healthyThreshold(2)
                .unhealthyThreshold(2)
                .timeout(3)
                .target("HTTP:8000/")
                .interval(30)
                .build())
            .listeners(
                LoadBalancerListenerArgs.builder()
                    .instancePort(8000)
                    .instanceProtocol("http")
                    .lbPort(80)
                    .lbProtocol("http")
                    .build(),
                LoadBalancerListenerArgs.builder()
                    .instancePort(8000)
                    .instanceProtocol("http")
                    .lbPort(443)
                    .lbProtocol("https")
                    .sslCertificateId("arn:aws:iam::123456789012:server-certificate/certName")
                    .build())
            .name("foobar-elb")
            .availabilityZones(
                "us-west-2a",
                "us-west-2b",
                "us-west-2c")
            .instances(foo.id())
            .crossZoneLoadBalancing(true)
            .idleTimeout(400)
            .connectionDraining(true)
            .connectionDrainingTimeout(400)
            .tags(Map.of("Name", "foobar-elb"))
            .build());

    }
}
resources:
  # Create a new load balancer
  bar:
    type: aws:elb:LoadBalancer
    properties:
      accessLogs:
        bucket: foo
        bucketPrefix: bar
        interval: 60
      healthCheck:
        healthyThreshold: 2
        unhealthyThreshold: 2
        timeout: 3
        target: HTTP:8000/
        interval: 30
      listeners:
        - instancePort: 8000
          instanceProtocol: http
          lbPort: 80
          lbProtocol: http
        - instancePort: 8000
          instanceProtocol: http
          lbPort: 443
          lbProtocol: https
          sslCertificateId: arn:aws:iam::123456789012:server-certificate/certName
      name: foobar-elb
      availabilityZones:
        - us-west-2a
        - us-west-2b
        - us-west-2c
      instances:
        - ${foo.id}
      crossZoneLoadBalancing: true
      idleTimeout: 400
      connectionDraining: true
      connectionDrainingTimeout: 400
      tags:
        Name: foobar-elb

Import

Identity Schema

Required

  • name (String) Name of the ELB.

Optional

  • accountId (String) AWS Account where this resource is managed.
  • region (String) Region where this resource is managed.

Using pulumi import, import ELBs using the name. For example:

$ pulumi import aws:elb/loadBalancer:LoadBalancer example elb-production-12345

Constructors

LoadBalancer(String name, {LoadBalancerArgs? args, CustomResourceOptions? options})
Creates a new LoadBalancer. name The Pulumi resource name. args Arguments used to configure this LoadBalancer. The set of arguments for LoadBalancer. options Resource options controlling this resource's behavior.
LoadBalancer.reference(String urn)
Creates a typed reference to an existing LoadBalancer resource.

Properties

accessLogs ↔ Output<LoadBalancerAccessLogs?>
An Access Logs block. Access Logs documented below.
latefinal
arn ↔ Output<String>
The ARN of the ELB
latefinal
availabilityZones ↔ Output<List<String>>
The AZ's to serve traffic in.
latefinal
childResources → Set<Resource>
finalinherited
completionSources ↔ Map<String, IOutputCompletionSource>
latefinalinherited
connectionDraining ↔ Output<bool?>
Boolean to enable connection draining. Default: false
latefinal
connectionDrainingTimeout ↔ Output<int?>
The time in seconds to allow for connections to drain. Default: 300
latefinal
crossZoneLoadBalancing ↔ Output<bool?>
Enable cross-zone load balancing. Default: true
latefinal
desyncMitigationMode ↔ Output<String?>
Determines 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>
The DNS name of the ELB
latefinal
hashCode → int
The hash code for this object.
no setterinherited
healthCheck ↔ Output<LoadBalancerHealthCheck>
A healthCheck block. Health Check documented below.
latefinal
id ↔ Output<String>
getter/setter pairinherited
idleTimeout ↔ Output<int?>
The time in seconds that the connection is allowed to be idle. Default: 60
latefinal
instances ↔ Output<List<String>>
A list of instance ids to place in the ELB pool.
latefinal
internal ↔ Output<bool>
If true, ELB will be an internal ELB.
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
listeners ↔ Output<List<LoadBalancerListener>>
A list of listener blocks. Listeners documented below.
latefinal
name ↔ Output<String>
The name of the ELB. By default generated by this provider.
latefinal
namePrefix ↔ Output<String>
Creates a unique name beginning with the specified prefix. Conflicts with name.
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
securityGroups ↔ Output<List<String>>
A list of security group IDs to assign to the ELB. Only valid if creating an ELB within a VPC
latefinal
sourceSecurityGroup ↔ Output<String>
The name of the security group that you can use as part of your inbound rules for your load balancer's back-end application instances. Use this for Classic or Default VPC only.
latefinal
sourceSecurityGroupId ↔ Output<String>
The ID of the security group that you can use as part of your inbound rules for your load balancer's back-end application instances. Only available on ELBs launched in a VPC.
latefinal
subnets ↔ Output<List<String>>
A list of subnet IDs to attach to the ELB. When an update to subnets will remove all current subnets, this will force a new resource.
latefinal
tags ↔ Output<Map<String, String>?>
A map of tags to assign to the resource. If configured with a provider defaultTags configuration block present, tags with matching keys will overwrite those defined at the provider-level.
latefinal
tagsAll ↔ Output<Map<String, String>>
A map of tags assigned to the resource, including those inherited from the provider defaultTags configuration block.
latefinal
transformations → List<ResourceTransformation>
Inherited/explicit legacy transformations.
no setterinherited
urn ↔ Output<String>
latefinalinherited
zoneId ↔ Output<String>
The canonical hosted zone ID of the ELB (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 name and id.