Skip to content
GitHubXDiscordRSS

TargetGroup

Learn how to create, update, and manage AWS Application Load Balancer TargetGroups using Alchemy Cloud Control.

The TargetGroup resource lets you manage AWS Application Load Balancer TargetGroups and their configuration settings.

Create a basic TargetGroup with required properties and a couple of common optional properties.

import AWS from "alchemy/aws/control";
const targetGroup = await AWS.ElasticLoadBalancingV2.TargetGroup("myTargetGroup", {
name: "my-app-target-group",
port: 80,
protocol: "HTTP",
vpcId: "vpc-12345678",
healthCheckEnabled: true,
healthCheckPath: "/health",
healthyThresholdCount: 3,
unhealthyThresholdCount: 2
});

Configure a TargetGroup with advanced settings, including health check configurations and target type.

const advancedTargetGroup = await AWS.ElasticLoadBalancingV2.TargetGroup("advancedTargetGroup", {
name: "my-advanced-app-target-group",
port: 8080,
protocol: "HTTP",
vpcId: "vpc-12345678",
healthCheckEnabled: true,
healthCheckPath: "/health",
healthCheckIntervalSeconds: 30,
healthCheckTimeoutSeconds: 5,
healthyThresholdCount: 5,
unhealthyThresholdCount: 2,
targets: [
{
id: "i-1234567890abcdef0",
port: 8080
}
],
targetType: "instance"
});

Create a TargetGroup that uses IP addresses as targets.

const ipTargetGroup = await AWS.ElasticLoadBalancingV2.TargetGroup("ipTargetGroup", {
name: "my-ip-target-group",
port: 80,
protocol: "HTTP",
vpcId: "vpc-12345678",
ipAddressType: "ipv4",
targets: [
{
id: "192.0.2.1",
port: 80
},
{
id: "192.0.2.2",
port: 80
}
],
healthCheckEnabled: true,
healthCheckPath: "/health"
});

Configure a TargetGroup with custom attributes for stickiness and deregistration delay.

const customAttributeTargetGroup = await AWS.ElasticLoadBalancingV2.TargetGroup("customAttrTargetGroup", {
name: "my-custom-attr-target-group",
port: 80,
protocol: "HTTP",
vpcId: "vpc-12345678",
targetGroupAttributes: [
{
key: "stickiness.enabled",
value: "true"
},
{
key: "stickiness.lb_cookie.duration_seconds",
value: "86400"
},
{
key: "deregistration_delay.timeout_seconds",
value: "300"
}
]
});