aws_elasticloadbalancingv2: Can't interact with the Network or Application Target Group from EcsTarget
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 71
Description
### Describe the feature
Maybe I've missed something, but if you do something like the following:
```python3
ecs_target = ecs.EcsTarget(
container_name="container_name",
container_port=80,
new_target_group_id="TargetGroup80",
listener=ecs.ListenerConfig.network_listener(
listener=nlb_listener_80,
port=80,
deregistration_delay=Duration.seconds(10),
),
)
# Register the target with the target group
nlb_flask_fargate_service.service.register_load_balancer_targets(ecs_target)
```
There's no way to further interact with the `lb.NetworkTargetGroup` or `lb.ApplicationTargetGroup`.
If you try to import the `TargetGroup` via the following, you need the full ARN which the above `EcsTarget` construct doesn't give you (just the `new_group_id`)
```python3
def import_80_target_group(self) -> None:
target_group_80 = lb.NetworkTargetGroup.from_target_group_attributes(
self,
"TargetGroup80Imported",
target_group_arn=ecs_target.new_target_group_id,
load_balancer_arns=nlb_flask_fargate_service.load_balancer.load_balancer_arn,
)
```
### Use Case
Add custom metrics / monitoring / alarms / scaling to the target group:
```python3
target_group_80.metrics.custom(metric_name="RequestCount", period=Duration.minutes(1)).create_alarm(
self,
"HighNumRequestsAlarm",
evaluation_periods=1,
threshold=20,
comparison_operator=cw.ComparisonOperator.GREATER_THAN_OR_EQUAL_TO_THRESHOLD,
alarm_description="ECS Scale up on Number of Incoming Requests if number of requests is greater than 20 in a minute",
)
```
```python3
scaling.scale_on_metric(
"TargetResponseTimeScaling",
metric=self.flask_nlb_fargate_service.target_group.metrics.target_response_time(),
scaling_steps=[
appscaling.ScalingInterval(lower=0, change=-1), # Decreases tasks if requests are low.
appscaling.ScalingInterval(lower=10.0, change=+1), # Scale out if response time > 10s, add a task
appscaling.ScalingInterval(lower=20.0, change=+2), # Scale out more if > 20s, add 2 tasks
],
adjustment_type=appscaling.AdjustmentType.CHANGE_IN_CAPACITY,
)
```
### Proposed Solution
Expose the underlying `TargetGroup` construct via a property on `EcsTarget` or at least the full ARN.
### Other Information
_No response_
### Acknowledgements
- [ ] I may be able to implement this feature request
- [ ] This feature might incur a breaking change
### CDK version used
2.180.0
### Environment details (OS name and version, etc.)
MacOS
Contributor guide
Research direction
Start at the EcsTarget construct and register_load_balancer_targets entry points, then inspect how the NetworkTargetGroup and ApplicationTargetGroup constructs are created. Compare whether exposing the underlying TargetGroup or its full ARN best supports the metrics, alarms, and scaling examples; done means callers can interact with that target group without reconstructing its ARN.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, typescript
- Domain
- cloud, infrastructure
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100