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.TargetGroupAttachmentis known asaws.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("test", {
targetType: "lambda",
});
const testFunction = new aws.lambda.Function("test", {});
const withLb = new aws.lambda.Permission("with_lb", {
action: "lambda:InvokeFunction",
function: testFunction.arn,
principal: "elasticloadbalancing.amazonaws.com",
sourceArn: testTargetGroup.arn,
});
const testTargetGroupAttachment = new aws.lb.TargetGroupAttachment("test", {
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")
with_lb = aws.lambda_.Permission("withLb",
action="lambda:InvokeFunction",
function=test_function.arn,
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=ResourceOptions(depends_on=["aws_lambda_permission.with_lb"]))using Pulumi;
using Aws = Pulumi.Aws;
class MyStack : Stack
{
public MyStack()
{
var testTargetGroup = new Aws.LB.TargetGroup("testTargetGroup", new Aws.LB.TargetGroupArgs
{
TargetType = "lambda",
});
var testFunction = new Aws.Lambda.Function("testFunction", new Aws.Lambda.FunctionArgs
{
});
var withLb = new Aws.Lambda.Permission("withLb", new Aws.Lambda.PermissionArgs
{
Action = "lambda:InvokeFunction",
Function = testFunction.Arn,
Principal = "elasticloadbalancing.amazonaws.com",
SourceArn = testTargetGroup.Arn,
});
var testTargetGroupAttachment = new Aws.LB.TargetGroupAttachment("testTargetGroupAttachment", new Aws.LB.TargetGroupAttachmentArgs
{
TargetGroupArn = testTargetGroup.Arn,
TargetId = testFunction.Arn,
}, new CustomResourceOptions
{
DependsOn =
{
"aws_lambda_permission.with_lb",
},
});
}
}
package main
import (
"github.com/pulumi/pulumi-aws/sdk/v2/go/aws/lambda"
"github.com/pulumi/pulumi-aws/sdk/v2/go/aws/lb"
"github.com/pulumi/pulumi/sdk/v2/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
}
_, err = lambda.NewPermission(ctx, "withLb", &lambda.PermissionArgs{
Action: pulumi.String("lambda:InvokeFunction"),
Function: testFunction.Arn,
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{
"aws_lambda_permission.with_lb",
}))
if err != nil {
return err
}
return nil
})
}Example Usage
using Pulumi;
using Aws = Pulumi.Aws;
class MyStack : Stack
{
public MyStack()
{
var testTargetGroup = new Aws.LB.TargetGroup("testTargetGroup", new Aws.LB.TargetGroupArgs
{
});
var testInstance = new Aws.Ec2.Instance("testInstance", new Aws.Ec2.InstanceArgs
{
});
var testTargetGroupAttachment = new Aws.LB.TargetGroupAttachment("testTargetGroupAttachment", new Aws.LB.TargetGroupAttachmentArgs
{
Port = 80,
TargetGroupArn = testTargetGroup.Arn,
TargetId = testInstance.Id,
});
}
}
package main
import (
"github.com/pulumi/pulumi-aws/sdk/v2/go/aws/ec2"
"github.com/pulumi/pulumi-aws/sdk/v2/go/aws/lb"
"github.com/pulumi/pulumi/sdk/v2/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{
Port: pulumi.Int(80),
TargetGroupArn: testTargetGroup.Arn,
TargetId: testInstance.ID(),
})
if err != nil {
return err
}
return nil
})
}import pulumi
import pulumi_aws as aws
test_target_group = aws.lb.TargetGroup("testTargetGroup")
test_instance = aws.ec2.Instance("testInstance")
test_target_group_attachment = aws.lb.TargetGroupAttachment("testTargetGroupAttachment",
port=80,
target_group_arn=test_target_group.arn,
target_id=test_instance.id)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 testTargetGroupAttachment = new aws.lb.TargetGroupAttachment("test", {
port: 80,
targetGroupArn: testTargetGroup.arn,
targetId: testInstance.id,
});Deprecated: aws.applicationloadbalancing.TargetGroupAttachment has been deprecated in favor of aws.alb.TargetGroupAttachment
Create a TargetGroupAttachment Resource
new TargetGroupAttachment(name: string, args: TargetGroupAttachmentArgs, opts?: CustomResourceOptions);def TargetGroupAttachment(resource_name, opts=None, availability_zone=None, port=None, target_group_arn=None, target_id=None, __props__=None);func NewTargetGroupAttachment(ctx *Context, name string, args TargetGroupAttachmentArgs, opts ...ResourceOption) (*TargetGroupAttachment, error)public TargetGroupAttachment(string name, TargetGroupAttachmentArgs args, CustomResourceOptions? opts = null)- 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.
- opts ResourceOptions
- A bag of options that control this 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.
TargetGroupAttachment Resource Properties
To learn more about resource properties and how to use them, see Inputs and Outputs in the Programming Model docs.
Inputs
The TargetGroupAttachment resource accepts the following input properties:
- Target
Group stringArn The ARN of the target group with which to register targets
- Target
Id 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.
- Availability
Zone string The Availability Zone where the IP address of the target is to be registered.
- Port int
The port on which targets receive traffic.
- Target
Group stringArn The ARN of the target group with which to register targets
- Target
Id 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.
- Availability
Zone string The Availability Zone where the IP address of the target is to be registered.
- Port int
The port on which targets receive traffic.
- target
Group stringArn The ARN of the target group with which to register targets
- target
Id 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.
- availability
Zone string The Availability Zone where the IP address of the target is to be registered.
- port number
The port on which targets receive traffic.
- target_
group_ strarn 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.
- availability_
zone str The Availability Zone where the IP address of the target is to be registered.
- port float
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:
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): TargetGroupAttachmentstatic get(resource_name, id, opts=None, availability_zone=None, port=None, target_group_arn=None, target_id=None, __props__=None);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)- 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.
The following state arguments are supported:
- Availability
Zone string The Availability Zone where the IP address of the target is to be registered.
- Port int
The port on which targets receive traffic.
- Target
Group stringArn The ARN of the target group with which to register targets
- Target
Id 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.
- Availability
Zone string The Availability Zone where the IP address of the target is to be registered.
- Port int
The port on which targets receive traffic.
- Target
Group stringArn The ARN of the target group with which to register targets
- Target
Id 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.
- availability
Zone string The Availability Zone where the IP address of the target is to be registered.
- port number
The port on which targets receive traffic.
- target
Group stringArn The ARN of the target group with which to register targets
- target
Id 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.
- availability_
zone str The Availability Zone where the IP address of the target is to be registered.
- port float
The port on which targets receive traffic.
- target_
group_ strarn 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.
Package Details
- Repository
- https://github.com/pulumi/pulumi-aws
- License
- Apache-2.0
- Notes
- This Pulumi package is based on the
awsTerraform Provider.