Target Group Attachment Args
data class TargetGroupAttachmentArgs(val availabilityZone: Output<String>? = null, val port: Output<Int>? = null, val targetGroupArn: Output<String>? = null, val targetId: Output<String>? = null) : ConvertibleToJava<TargetGroupAttachmentArgs>
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.TargetGroupAttachmentis known asaws.lb.TargetGroupAttachment. The functionality is identical.
Example Usage
Basic Usage
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
const testTargetGroup = new aws.lb.TargetGroup("test", {});
const testInstance = new aws.ec2.Instance("test", {});
const test = new aws.lb.TargetGroupAttachment("test", {
targetGroupArn: testTargetGroup.arn,
targetId: testInstance.id,
port: 80,
});Content copied to clipboard
import pulumi
import pulumi_aws as aws
test_target_group = aws.lb.TargetGroup("test")
test_instance = aws.ec2.Instance("test")
test = aws.lb.TargetGroupAttachment("test",
target_group_arn=test_target_group.arn,
target_id=test_instance.id,
port=80)Content copied to clipboard
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;
return await Deployment.RunAsync(() =>
{
var testTargetGroup = new Aws.LB.TargetGroup("test");
var testInstance = new Aws.Ec2.Instance("test");
var test = new Aws.LB.TargetGroupAttachment("test", new()
{
TargetGroupArn = testTargetGroup.Arn,
TargetId = testInstance.Id,
Port = 80,
});
});Content copied to clipboard
package main
import (
"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/ec2"
"github.com/pulumi/pulumi-aws/sdk/v6/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, "test", nil)
if err != nil {
return err
}
testInstance, err := ec2.NewInstance(ctx, "test", nil)
if err != nil {
return err
}
_, err = lb.NewTargetGroupAttachment(ctx, "test", &lb.TargetGroupAttachmentArgs{
TargetGroupArn: testTargetGroup.Arn,
TargetId: testInstance.ID(),
Port: pulumi.Int(80),
})
if err != nil {
return err
}
return nil
})
}Content copied to clipboard
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 test = new TargetGroupAttachment("test", TargetGroupAttachmentArgs.builder()
.targetGroupArn(testTargetGroup.arn())
.targetId(testInstance.id())
.port(80)
.build());
}
}Content copied to clipboard
resources:
test:
type: aws:lb:TargetGroupAttachment
properties:
targetGroupArn: ${testTargetGroup.arn}
targetId: ${testInstance.id}
port: 80
testTargetGroup:
type: aws:lb:TargetGroup
name: test
testInstance:
type: aws:ec2:Instance
name: testContent copied to clipboard
Lambda Target
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
const test = new aws.lb.TargetGroup("test", {
name: "test",
targetType: "lambda",
});
const testFunction = new aws.lambda.Function("test", {});
const withLb = new aws.lambda.Permission("with_lb", {
statementId: "AllowExecutionFromlb",
action: "lambda:InvokeFunction",
"function": testFunction.name,
principal: "elasticloadbalancing.amazonaws.com",
sourceArn: test.arn,
});
const testTargetGroupAttachment = new aws.lb.TargetGroupAttachment("test", {
targetGroupArn: test.arn,
targetId: testFunction.arn,
}, {
dependsOn: [withLb],
});Content copied to clipboard
import pulumi
import pulumi_aws as aws
test = aws.lb.TargetGroup("test",
name="test",
target_type="lambda")
test_function = aws.lambda_.Function("test")
with_lb = aws.lambda_.Permission("with_lb",
statement_id="AllowExecutionFromlb",
action="lambda:InvokeFunction",
function=test_function.name,
principal="elasticloadbalancing.amazonaws.com",
source_arn=test.arn)
test_target_group_attachment = aws.lb.TargetGroupAttachment("test",
target_group_arn=test.arn,
target_id=test_function.arn,
opts=pulumi.ResourceOptions(depends_on=[with_lb]))Content copied to clipboard
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;
return await Deployment.RunAsync(() =>
{
var test = new Aws.LB.TargetGroup("test", new()
{
Name = "test",
TargetType = "lambda",
});
var testFunction = new Aws.Lambda.Function("test");
var withLb = new Aws.Lambda.Permission("with_lb", new()
{
StatementId = "AllowExecutionFromlb",
Action = "lambda:InvokeFunction",
Function = testFunction.Name,
Principal = "elasticloadbalancing.amazonaws.com",
SourceArn = test.Arn,
});
var testTargetGroupAttachment = new Aws.LB.TargetGroupAttachment("test", new()
{
TargetGroupArn = test.Arn,
TargetId = testFunction.Arn,
}, new CustomResourceOptions
{
DependsOn =
{
withLb,
},
});
});Content copied to clipboard
package main
import (
"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/lambda"
"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/lb"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
test, err := lb.NewTargetGroup(ctx, "test", &lb.TargetGroupArgs{
Name: pulumi.String("test"),
TargetType: pulumi.String("lambda"),
})
if err != nil {
return err
}
testFunction, err := lambda.NewFunction(ctx, "test", nil)
if err != nil {
return err
}
withLb, err := lambda.NewPermission(ctx, "with_lb", &lambda.PermissionArgs{
StatementId: pulumi.String("AllowExecutionFromlb"),
Action: pulumi.String("lambda:InvokeFunction"),
Function: testFunction.Name,
Principal: pulumi.String("elasticloadbalancing.amazonaws.com"),
SourceArn: test.Arn,
})
if err != nil {
return err
}
_, err = lb.NewTargetGroupAttachment(ctx, "test", &lb.TargetGroupAttachmentArgs{
TargetGroupArn: test.Arn,
TargetId: testFunction.Arn,
}, pulumi.DependsOn([]pulumi.Resource{
withLb,
}))
if err != nil {
return err
}
return nil
})
}Content copied to clipboard
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 test = new TargetGroup("test", TargetGroupArgs.builder()
.name("test")
.targetType("lambda")
.build());
var testFunction = new Function("testFunction");
var withLb = new Permission("withLb", PermissionArgs.builder()
.statementId("AllowExecutionFromlb")
.action("lambda:InvokeFunction")
.function(testFunction.name())
.principal("elasticloadbalancing.amazonaws.com")
.sourceArn(test.arn())
.build());
var testTargetGroupAttachment = new TargetGroupAttachment("testTargetGroupAttachment", TargetGroupAttachmentArgs.builder()
.targetGroupArn(test.arn())
.targetId(testFunction.arn())
.build(), CustomResourceOptions.builder()
.dependsOn(withLb)
.build());
}
}Content copied to clipboard
resources:
withLb:
type: aws:lambda:Permission
name: with_lb
properties:
statementId: AllowExecutionFromlb
action: lambda:InvokeFunction
function: ${testFunction.name}
principal: elasticloadbalancing.amazonaws.com
sourceArn: ${test.arn}
test:
type: aws:lb:TargetGroup
properties:
name: test
targetType: lambda
testFunction:
type: aws:lambda:Function
name: test
testTargetGroupAttachment:
type: aws:lb:TargetGroupAttachment
name: test
properties:
targetGroupArn: ${test.arn}
targetId: ${testFunction.arn}
options:
dependson:
- ${withLb}Content copied to clipboard
Registering Multiple Targets
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
const example: aws.ec2.Instance[] = [];
for (const range = {value: 0}; range.value < 3; range.value++) {
example.push(new aws.ec2.Instance(`example-${range.value}`, {}));
}
const exampleTargetGroup = new aws.lb.TargetGroup("example", {});
const exampleTargetGroupAttachment: aws.lb.TargetGroupAttachment[] = [];
pulumi.all(example.map((v, k) => [k, v]).reduce((__obj, [, ]) => ({ ...__obj, [k]: v }))).apply(rangeBody => {
for (const range of Object.entries(rangeBody).map(([k, v]) => ({key: k, value: v}))) {
exampleTargetGroupAttachment.push(new aws.lb.TargetGroupAttachment(`example-${range.key}`, {
targetGroupArn: exampleTargetGroup.arn,
targetId: range.value.id,
port: 80,
}));
}
});Content copied to clipboard
import pulumi
import pulumi_aws as aws
example = []
for range in [{"value": i} for i in range(0, 3)]:
example.append(aws.ec2.Instance(f"example-{range['value']}"))
example_target_group = aws.lb.TargetGroup("example")
example_target_group_attachment = []
def create_example(range_body):
for range in [{"key": k, "value": v} for [k, v] in enumerate(range_body)]:
example_target_group_attachment.append(aws.lb.TargetGroupAttachment(f"example-{range['key']}",
target_group_arn=example_target_group.arn,
target_id=range["value"],
port=80))
pulumi.Output.all({k: v for k, v in example}).apply(lambda resolved_outputs: create_example(resolved_outputs[0]))Content copied to clipboard
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;
return await Deployment.RunAsync(() =>
{
var example = new List<Aws.Ec2.Instance>();
for (var rangeIndex = 0; rangeIndex < 3; rangeIndex++)
{
var range = new { Value = rangeIndex };
example.Add(new Aws.Ec2.Instance($"example-{range.Value}", new()
{
}));
}
var exampleTargetGroup = new Aws.LB.TargetGroup("example");
var exampleTargetGroupAttachment = new List<Aws.LB.TargetGroupAttachment>();
foreach (var range in example.Select((value, i) => new { Key = i.ToString(), Value = pair.Value }).Select(pair => new { pair.Key, pair.Value }))
{
exampleTargetGroupAttachment.Add(new Aws.LB.TargetGroupAttachment($"example-{range.Key}", new()
{
TargetGroupArn = exampleTargetGroup.Arn,
TargetId = range.Value.Id,
Port = 80,
}));
}
});Content copied to clipboard
resources:
example:
type: aws:ec2:Instance
options: {}
exampleTargetGroup:
type: aws:lb:TargetGroup
name: example
exampleTargetGroupAttachment:
type: aws:lb:TargetGroupAttachment
name: example
properties:
targetGroupArn: ${exampleTargetGroup.arn}
targetId: ${range.value.id}
port: 80
options: {}Content copied to clipboard
Import
You cannot import Target Group Attachments.
Constructors
Link copied to clipboard
fun TargetGroupAttachmentArgs(availabilityZone: Output<String>? = null, port: Output<Int>? = null, targetGroupArn: Output<String>? = null, targetId: Output<String>? = null)
Functions
Properties
Link copied to clipboard
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 Lambda function ARN. If the target type is alb, specify the ALB ARN. The following arguments are optional: