Issues attaching ASG to an existing ALB listener #26136
-
As part of a larger migration of existing assets into a CDK-managed stack, I have to spin up a new ASG, attached to a load balancer, using the Python flavour of the CDK. This is the approach I've followed (ignoring the lookup of additional resources, such as the VPC and SGs): # ASG creation.
asg = aws_autoscaling.AutoScalingGroup(
self,
"appGroupDev",
vpc=vpc,
role=role,
instance_type=aws_ec2.InstanceType("t3.micro"),
machine_image=ami,
user_data=user_data,
key_name="app_key",
block_devices=[
aws_autoscaling.BlockDevice(
device_name="/dev/sda1",
volume=aws_autoscaling.BlockDeviceVolume.ebs(
volume_size=100,
delete_on_termination=True,
),
),
],
desired_capacity=1,
min_capacity=1,
max_capacity=3,
)
asg.add_security_group(sg[0])
asg.add_security_group(sg[1])
# Target group creation.
target_group = aws_elasticloadbalancingv2.ApplicationTargetGroup(
self,
"appTargetGroup",
vpc=vpc,
targets=[asg], # Registration.
health_check=aws_elasticloadbalancingv2.HealthCheck(
path="/healthcheck",
port="8080",
),
deregistration_delay=Duration.seconds(0),
)
# Listener attachment.
listener = aws_elasticloadbalancingv2.ApplicationListener.from_lookup(
self,
"appHttpListener",
listener_arn=LISTENER_ARN,
)
listener.add_target_groups(
"appTargetGroupAttachment",
target_groups=[target_group],
conditions=[
aws_elasticloadbalancingv2.ListenerCondition.path_patterns(
values=["/app*"]
),
],
priority=10,
) Unfortunately, this does not work, and complains on
If I remove the asg.attach_to_application_target_group(target_group) I still get the exact same problem. I wonder whether mixing new and existing resources is the problem here, and I need a slightly different incantation, I am doing something that's off enough to cause this, or this is a legitimate issue. Could anyone point me in the right direction? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Either your port or protocol must be defined on your |
Beta Was this translation helpful? Give feedback.
-
Hello! Reopening this discussion to make it searchable. |
Beta Was this translation helpful? Give feedback.
Either your port or protocol must be defined on your
ApplicationTargetGroup
, so that the port can be known. The implementation we have is a bit buggy in that we are running this code without first verifying that the port is defined, leading to an unhelpful error messageaws-cdk/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/alb/application-target-group.ts
Lines 409 to 410 in 4e0d726