Target Group Attachment
Deprecated
aws.elasticloadbalancingv2.TargetGroupAttachment has been deprecated in favor of aws.lb.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 asaws.lb.TargetGroupAttachment
. The functionality is identical.
Example Usage
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());
}
}
Content copied to clipboard
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],
});
Content copied to clipboard
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]))
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("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,
},
});
});
Content copied to clipboard
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
})
}
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 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());
}
}
Content copied to clipboard
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}
Content copied to clipboard
Import
Target Group Attachments cannot be imported.
Properties
Link copied to clipboard
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'.
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
The ARN of the target group with which to register targets
Link copied to clipboard