Skip to content

Resource: awsLbTargetGroupAttachment

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 awsElbAttachment resource.

\~> Note: awsAlbTargetGroupAttachment is known as awsLbTargetGroupAttachment. The functionality is identical.

Example Usage

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
const awsInstanceTest = new aws.instance.Instance(this, "test", {});
const awsLbTargetGroupTest = new aws.lbTargetGroup.LbTargetGroup(
  this,
  "test_1",
  {}
);
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
awsLbTargetGroupTest.overrideLogicalId("test");
const awsLbTargetGroupAttachmentTest =
  new aws.lbTargetGroupAttachment.LbTargetGroupAttachment(this, "test_2", {
    port: 80,
    targetGroupArn: awsLbTargetGroupTest.arn,
    targetId: awsInstanceTest.id,
  });
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
awsLbTargetGroupAttachmentTest.overrideLogicalId("test");

Usage with lambda

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
const awsLambdaFunctionTest = new aws.lambdaFunction.LambdaFunction(
  this,
  "test",
  {}
);
const awsLbTargetGroupTest = new aws.lbTargetGroup.LbTargetGroup(
  this,
  "test_1",
  {
    name: "test",
    targetType: "lambda",
  }
);
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
awsLbTargetGroupTest.overrideLogicalId("test");
const awsLambdaPermissionWithLb = new aws.lambdaPermission.LambdaPermission(
  this,
  "with_lb",
  {
    action: "lambda:InvokeFunction",
    functionName: awsLambdaFunctionTest.functionName,
    principal: "elasticloadbalancing.amazonaws.com",
    sourceArn: awsLbTargetGroupTest.arn,
    statementId: "AllowExecutionFromlb",
  }
);
const awsLbTargetGroupAttachmentTest =
  new aws.lbTargetGroupAttachment.LbTargetGroupAttachment(this, "test_3", {
    depends_on: [`\${${awsLambdaPermissionWithLb.fqn}}`],
    targetGroupArn: awsLbTargetGroupTest.arn,
    targetId: awsLambdaFunctionTest.arn,
  });
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
awsLbTargetGroupAttachmentTest.overrideLogicalId("test");

Argument Reference

The following arguments are supported:

  • targetGroupArn - (Required) The ARN of the target group with which to register targets
  • targetId (Required) 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.
  • port - (Optional) The port on which targets receive traffic.
  • availabilityZone - (Optional) 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'.

Attributes Reference

In addition to all arguments above, the following attributes are exported:

  • id - A unique identifier for the attachment

Import

Target Group Attachments cannot be imported.