AWS Classic

v5.16.2 published on Tuesday, Oct 4, 2022 by Pulumi

TargetGroupAttachment

Deprecated:

aws.applicationloadbalancing.TargetGroupAttachment has been deprecated in favor of aws.alb.TargetGroupAttachment

Provides the ability to register instances and containers with an Application Load Balancer (ALB) or Network Load Balancer (NLB) target group. For attaching resources with Elastic Load Balancer (ELB), see the aws.elb.Attachment resource.

Note: aws.alb.TargetGroupAttachment is known as aws.lb.TargetGroupAttachment. The functionality is identical.

Usage with lambda

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

const testTargetGroup = new aws.lb.TargetGroup("testTargetGroup", {targetType: "lambda"});
const testFunction = new aws.lambda.Function("testFunction", {});
// ... other configuration ...
const withLb = new aws.lambda.Permission("withLb", {
    action: "lambda:InvokeFunction",
    "function": testFunction.name,
    principal: "elasticloadbalancing.amazonaws.com",
    sourceArn: testTargetGroup.arn,
});
const testTargetGroupAttachment = new aws.lb.TargetGroupAttachment("testTargetGroupAttachment", {
    targetGroupArn: testTargetGroup.arn,
    targetId: testFunction.arn,
}, {
    dependsOn: [withLb],
});
import pulumi
import pulumi_aws as aws

test_target_group = aws.lb.TargetGroup("testTargetGroup", target_type="lambda")
test_function = aws.lambda_.Function("testFunction")
# ... other configuration ...
with_lb = aws.lambda_.Permission("withLb",
    action="lambda:InvokeFunction",
    function=test_function.name,
    principal="elasticloadbalancing.amazonaws.com",
    source_arn=test_target_group.arn)
test_target_group_attachment = aws.lb.TargetGroupAttachment("testTargetGroupAttachment",
    target_group_arn=test_target_group.arn,
    target_id=test_function.arn,
    opts=pulumi.ResourceOptions(depends_on=[with_lb]))
using System.Collections.Generic;
using Pulumi;
using Aws = Pulumi.Aws;

return await Deployment.RunAsync(() => 
{
    var testTargetGroup = new Aws.LB.TargetGroup("testTargetGroup", new()
    {
        TargetType = "lambda",
    });

    var testFunction = new Aws.Lambda.Function("testFunction");

    // ... other configuration ...
    var withLb = new Aws.Lambda.Permission("withLb", new()
    {
        Action = "lambda:InvokeFunction",
        Function = testFunction.Name,
        Principal = "elasticloadbalancing.amazonaws.com",
        SourceArn = testTargetGroup.Arn,
    });

    var testTargetGroupAttachment = new Aws.LB.TargetGroupAttachment("testTargetGroupAttachment", new()
    {
        TargetGroupArn = testTargetGroup.Arn,
        TargetId = testFunction.Arn,
    }, new CustomResourceOptions
    {
        DependsOn = new[]
        {
            withLb,
        },
    });

});
package main

import (
	"github.com/pulumi/pulumi-aws/sdk/v5/go/aws/lambda"
	"github.com/pulumi/pulumi-aws/sdk/v5/go/aws/lb"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		testTargetGroup, err := lb.NewTargetGroup(ctx, "testTargetGroup", &lb.TargetGroupArgs{
			TargetType: pulumi.String("lambda"),
		})
		if err != nil {
			return err
		}
		testFunction, err := lambda.NewFunction(ctx, "testFunction", nil)
		if err != nil {
			return err
		}
		withLb, err := lambda.NewPermission(ctx, "withLb", &lambda.PermissionArgs{
			Action:    pulumi.String("lambda:InvokeFunction"),
			Function:  testFunction.Name,
			Principal: pulumi.String("elasticloadbalancing.amazonaws.com"),
			SourceArn: testTargetGroup.Arn,
		})
		if err != nil {
			return err
		}
		_, err = lb.NewTargetGroupAttachment(ctx, "testTargetGroupAttachment", &lb.TargetGroupAttachmentArgs{
			TargetGroupArn: testTargetGroup.Arn,
			TargetId:       testFunction.Arn,
		}, pulumi.DependsOn([]pulumi.Resource{
			withLb,
		}))
		if err != nil {
			return err
		}
		return nil
	})
}
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.lb.TargetGroup;
import com.pulumi.aws.lb.TargetGroupArgs;
import com.pulumi.aws.lambda.Function;
import com.pulumi.aws.lambda.Permission;
import com.pulumi.aws.lambda.PermissionArgs;
import com.pulumi.aws.lb.TargetGroupAttachment;
import com.pulumi.aws.lb.TargetGroupAttachmentArgs;
import com.pulumi.resources.CustomResourceOptions;
import java.util.List;
import java.util.ArrayList;
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 testTargetGroup = new TargetGroup("testTargetGroup", TargetGroupArgs.builder()        
            .targetType("lambda")
            .build());

        var testFunction = new Function("testFunction");

        var withLb = new Permission("withLb", PermissionArgs.builder()        
            .action("lambda:InvokeFunction")
            .function(testFunction.name())
            .principal("elasticloadbalancing.amazonaws.com")
            .sourceArn(testTargetGroup.arn())
            .build());

        var testTargetGroupAttachment = new TargetGroupAttachment("testTargetGroupAttachment", TargetGroupAttachmentArgs.builder()        
            .targetGroupArn(testTargetGroup.arn())
            .targetId(testFunction.arn())
            .build(), CustomResourceOptions.builder()
                .dependsOn(withLb)
                .build());

    }
}
resources:
  withLb:
    type: aws:lambda:Permission
    properties:
      action: lambda:InvokeFunction
      function: ${testFunction.name}
      principal: elasticloadbalancing.amazonaws.com
      sourceArn: ${testTargetGroup.arn}
  testTargetGroup:
    type: aws:lb:TargetGroup
    properties:
      targetType: lambda
  testFunction:
    type: aws:lambda:Function
  testTargetGroupAttachment:
    type: aws:lb:TargetGroupAttachment
    properties:
      targetGroupArn: ${testTargetGroup.arn}
      targetId: ${testFunction.arn}
    options:
      dependson:
        - ${withLb}

Example Usage

using System.Collections.Generic;
using Pulumi;
using Aws = Pulumi.Aws;

return await Deployment.RunAsync(() => 
{
    var testTargetGroup = new Aws.LB.TargetGroup("testTargetGroup");

    // ... other configuration ...
    var testInstance = new Aws.Ec2.Instance("testInstance");

    // ... other configuration ...
    var testTargetGroupAttachment = new Aws.LB.TargetGroupAttachment("testTargetGroupAttachment", new()
    {
        TargetGroupArn = testTargetGroup.Arn,
        TargetId = testInstance.Id,
        Port = 80,
    });

});
package main

import (
	"github.com/pulumi/pulumi-aws/sdk/v5/go/aws/ec2"
	"github.com/pulumi/pulumi-aws/sdk/v5/go/aws/lb"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		testTargetGroup, err := lb.NewTargetGroup(ctx, "testTargetGroup", nil)
		if err != nil {
			return err
		}
		testInstance, err := ec2.NewInstance(ctx, "testInstance", nil)
		if err != nil {
			return err
		}
		_, err = lb.NewTargetGroupAttachment(ctx, "testTargetGroupAttachment", &lb.TargetGroupAttachmentArgs{
			TargetGroupArn: testTargetGroup.Arn,
			TargetId:       testInstance.ID(),
			Port:           pulumi.Int(80),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.lb.TargetGroup;
import com.pulumi.aws.ec2.Instance;
import com.pulumi.aws.lb.TargetGroupAttachment;
import com.pulumi.aws.lb.TargetGroupAttachmentArgs;
import java.util.List;
import java.util.ArrayList;
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 testTargetGroup = new TargetGroup("testTargetGroup");

        var testInstance = new Instance("testInstance");

        var testTargetGroupAttachment = new TargetGroupAttachment("testTargetGroupAttachment", TargetGroupAttachmentArgs.builder()        
            .targetGroupArn(testTargetGroup.arn())
            .targetId(testInstance.id())
            .port(80)
            .build());

    }
}
import pulumi
import pulumi_aws as aws

test_target_group = aws.lb.TargetGroup("testTargetGroup")
# ... other configuration ...
test_instance = aws.ec2.Instance("testInstance")
# ... other configuration ...
test_target_group_attachment = aws.lb.TargetGroupAttachment("testTargetGroupAttachment",
    target_group_arn=test_target_group.arn,
    target_id=test_instance.id,
    port=80)
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const testTargetGroup = new aws.lb.TargetGroup("testTargetGroup", {});
// ... other configuration ...
const testInstance = new aws.ec2.Instance("testInstance", {});
// ... other configuration ...
const testTargetGroupAttachment = new aws.lb.TargetGroupAttachment("testTargetGroupAttachment", {
    targetGroupArn: testTargetGroup.arn,
    targetId: testInstance.id,
    port: 80,
});
resources:
  testTargetGroupAttachment:
    type: aws:lb:TargetGroupAttachment
    properties:
      targetGroupArn: ${testTargetGroup.arn}
      targetId: ${testInstance.id}
      port: 80
  testTargetGroup:
    type: aws:lb:TargetGroup
  testInstance:
    type: aws:ec2:Instance

Create a TargetGroupAttachment Resource

new TargetGroupAttachment(name: string, args: TargetGroupAttachmentArgs, opts?: CustomResourceOptions);
@overload
def TargetGroupAttachment(resource_name: str,
                          opts: Optional[ResourceOptions] = None,
                          availability_zone: Optional[str] = None,
                          port: Optional[int] = None,
                          target_group_arn: Optional[str] = None,
                          target_id: Optional[str] = None)
@overload
def TargetGroupAttachment(resource_name: str,
                          args: TargetGroupAttachmentArgs,
                          opts: Optional[ResourceOptions] = None)
func NewTargetGroupAttachment(ctx *Context, name string, args TargetGroupAttachmentArgs, opts ...ResourceOption) (*TargetGroupAttachment, error)
public TargetGroupAttachment(string name, TargetGroupAttachmentArgs args, CustomResourceOptions? opts = null)
public TargetGroupAttachment(String name, TargetGroupAttachmentArgs args)
public TargetGroupAttachment(String name, TargetGroupAttachmentArgs args, CustomResourceOptions options)
type: aws:applicationloadbalancing:TargetGroupAttachment
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.

name string
The unique name of the resource.
args TargetGroupAttachmentArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
resource_name str
The unique name of the resource.
args TargetGroupAttachmentArgs
The arguments to resource properties.
opts ResourceOptions
Bag of options to control resource's behavior.
ctx Context
Context object for the current deployment.
name string
The unique name of the resource.
args TargetGroupAttachmentArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name string
The unique name of the resource.
args TargetGroupAttachmentArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
name String
The unique name of the resource.
args TargetGroupAttachmentArgs
The arguments to resource properties.
options CustomResourceOptions
Bag of options to control resource's behavior.

TargetGroupAttachment Resource Properties

To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

Inputs

The TargetGroupAttachment resource accepts the following input properties:

TargetGroupArn string

The ARN of the target group with which to register targets

TargetId string

The ID of the target. This is the Instance ID for an instance, or the container ID for an ECS container. If the target type is ip, specify an IP address. If the target type is lambda, specify the arn of lambda. If the target type is alb, specify the arn of alb.

AvailabilityZone string

The Availability Zone where the IP address of the target is to be registered. If the private ip address is outside of the VPC scope, this value must be set to 'all'.

Port int

The port on which targets receive traffic.

TargetGroupArn string

The ARN of the target group with which to register targets

TargetId string

The ID of the target. This is the Instance ID for an instance, or the container ID for an ECS container. If the target type is ip, specify an IP address. If the target type is lambda, specify the arn of lambda. If the target type is alb, specify the arn of alb.

AvailabilityZone string

The Availability Zone where the IP address of the target is to be registered. If the private ip address is outside of the VPC scope, this value must be set to 'all'.

Port int

The port on which targets receive traffic.

targetGroupArn String

The ARN of the target group with which to register targets

targetId String

The ID of the target. This is the Instance ID for an instance, or the container ID for an ECS container. If the target type is ip, specify an IP address. If the target type is lambda, specify the arn of lambda. If the target type is alb, specify the arn of alb.

availabilityZone String

The Availability Zone where the IP address of the target is to be registered. If the private ip address is outside of the VPC scope, this value must be set to 'all'.

port Integer

The port on which targets receive traffic.

targetGroupArn string

The ARN of the target group with which to register targets

targetId string

The ID of the target. This is the Instance ID for an instance, or the container ID for an ECS container. If the target type is ip, specify an IP address. If the target type is lambda, specify the arn of lambda. If the target type is alb, specify the arn of alb.

availabilityZone string

The Availability Zone where the IP address of the target is to be registered. If the private ip address is outside of the VPC scope, this value must be set to 'all'.

port number

The port on which targets receive traffic.

target_group_arn str

The ARN of the target group with which to register targets

target_id str

The ID of the target. This is the Instance ID for an instance, or the container ID for an ECS container. If the target type is ip, specify an IP address. If the target type is lambda, specify the arn of lambda. If the target type is alb, specify the arn of alb.

availability_zone str

The Availability Zone where the IP address of the target is to be registered. If the private ip address is outside of the VPC scope, this value must be set to 'all'.

port int

The port on which targets receive traffic.

targetGroupArn String

The ARN of the target group with which to register targets

targetId String

The ID of the target. This is the Instance ID for an instance, or the container ID for an ECS container. If the target type is ip, specify an IP address. If the target type is lambda, specify the arn of lambda. If the target type is alb, specify the arn of alb.

availabilityZone String

The Availability Zone where the IP address of the target is to be registered. If the private ip address is outside of the VPC scope, this value must be set to 'all'.

port Number

The port on which targets receive traffic.

Outputs

All input properties are implicitly available as output properties. Additionally, the TargetGroupAttachment resource produces the following output properties:

Id string

The provider-assigned unique ID for this managed resource.

Id string

The provider-assigned unique ID for this managed resource.

id String

The provider-assigned unique ID for this managed resource.

id string

The provider-assigned unique ID for this managed resource.

id str

The provider-assigned unique ID for this managed resource.

id String

The provider-assigned unique ID for this managed resource.

Look up an Existing TargetGroupAttachment Resource

Get an existing TargetGroupAttachment resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.

public static get(name: string, id: Input<ID>, state?: TargetGroupAttachmentState, opts?: CustomResourceOptions): TargetGroupAttachment
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        availability_zone: Optional[str] = None,
        port: Optional[int] = None,
        target_group_arn: Optional[str] = None,
        target_id: Optional[str] = None) -> TargetGroupAttachment
func GetTargetGroupAttachment(ctx *Context, name string, id IDInput, state *TargetGroupAttachmentState, opts ...ResourceOption) (*TargetGroupAttachment, error)
public static TargetGroupAttachment Get(string name, Input<string> id, TargetGroupAttachmentState? state, CustomResourceOptions? opts = null)
public static TargetGroupAttachment get(String name, Output<String> id, TargetGroupAttachmentState state, CustomResourceOptions options)
Resource lookup is not supported in YAML
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
resource_name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
The following state arguments are supported:
AvailabilityZone string

The Availability Zone where the IP address of the target is to be registered. If the private ip address is outside of the VPC scope, this value must be set to 'all'.

Port int

The port on which targets receive traffic.

TargetGroupArn string

The ARN of the target group with which to register targets

TargetId string

The ID of the target. This is the Instance ID for an instance, or the container ID for an ECS container. If the target type is ip, specify an IP address. If the target type is lambda, specify the arn of lambda. If the target type is alb, specify the arn of alb.

AvailabilityZone string

The Availability Zone where the IP address of the target is to be registered. If the private ip address is outside of the VPC scope, this value must be set to 'all'.

Port int

The port on which targets receive traffic.

TargetGroupArn string

The ARN of the target group with which to register targets

TargetId string

The ID of the target. This is the Instance ID for an instance, or the container ID for an ECS container. If the target type is ip, specify an IP address. If the target type is lambda, specify the arn of lambda. If the target type is alb, specify the arn of alb.

availabilityZone String

The Availability Zone where the IP address of the target is to be registered. If the private ip address is outside of the VPC scope, this value must be set to 'all'.

port Integer

The port on which targets receive traffic.

targetGroupArn String

The ARN of the target group with which to register targets

targetId String

The ID of the target. This is the Instance ID for an instance, or the container ID for an ECS container. If the target type is ip, specify an IP address. If the target type is lambda, specify the arn of lambda. If the target type is alb, specify the arn of alb.

availabilityZone string

The Availability Zone where the IP address of the target is to be registered. If the private ip address is outside of the VPC scope, this value must be set to 'all'.

port number

The port on which targets receive traffic.

targetGroupArn string

The ARN of the target group with which to register targets

targetId string

The ID of the target. This is the Instance ID for an instance, or the container ID for an ECS container. If the target type is ip, specify an IP address. If the target type is lambda, specify the arn of lambda. If the target type is alb, specify the arn of alb.

availability_zone str

The Availability Zone where the IP address of the target is to be registered. If the private ip address is outside of the VPC scope, this value must be set to 'all'.

port int

The port on which targets receive traffic.

target_group_arn str

The ARN of the target group with which to register targets

target_id str

The ID of the target. This is the Instance ID for an instance, or the container ID for an ECS container. If the target type is ip, specify an IP address. If the target type is lambda, specify the arn of lambda. If the target type is alb, specify the arn of alb.

availabilityZone String

The Availability Zone where the IP address of the target is to be registered. If the private ip address is outside of the VPC scope, this value must be set to 'all'.

port Number

The port on which targets receive traffic.

targetGroupArn String

The ARN of the target group with which to register targets

targetId String

The ID of the target. This is the Instance ID for an instance, or the container ID for an ECS container. If the target type is ip, specify an IP address. If the target type is lambda, specify the arn of lambda. If the target type is alb, specify the arn of alb.

Import

Target Group Attachments cannot be imported.

Package Details

Repository
https://github.com/pulumi/pulumi-aws
License
Apache-2.0
Notes

This Pulumi package is based on the aws Terraform Provider.