aws-ecs: Resource handler returned message: "Invalid request provided: The target group with targetGroupArn <redacted> does not have an associated load balancer."
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
### Describe the bug
With [this](https://github.com/aws/aws-cdk/issues/5583#issuecomment-2825719363) workaround for redirecting HTTP to HTTPS on an ALB, I indeterminately experience the following:
```text
CoreStackDev | 28/70 | 5:02:27 PM | UPDATE_FAILED | AWS::ECS::Service | WebAppSvc/FlaskAppService/ControlPlane/ApplicationLoadBalancerFargateSvc/AlbFargateSvc/Service/Service (WebAppSvcFlaskAppServiceControlPlaneApplicationLoadBalancerFargateSvcAlbFargateSvcServiceADE54F9D) Resource handler returned message: "Invalid request provided: The target group with targetGroupArn does not have an associated load balancer. (Service: Ecs, Status Code: 400, Request ID: 91fd6146-d2f3-4534-bbdb-893469be2a1d) (SDK Attempt Count: 1)" (RequestToken: 25bc3e51-6110-4b81-8256-f4c02c60a863, HandlerErrorCode: InvalidRequest)
```
I tested redeploying multiple times (and changing the ECS Service, ALB, Task definition logicalids to recreate the resources) to no avail.
It looks like there's either:
1. A race condition ([regression](https://github.com/aws/aws-cdk/issues/1160))? somewhere. What's strange is this was working fine for a few days with multiple successful redeployments in between the original deployment and experiencing the error.
2. Some other reason why cloudformation thinks an old ALB target group exists when it does not
After removing the listener redirection (`lb.ListenerAction.redirect`) the deployment succeeded again.
My [ticket](https://github.com/aws/aws-cdk/issues/34235) is related.
### Regression Issue
- [ ] Select this option if this issue appears to be a regression.
### Last Known Working CDK Version
_No response_
### Expected Behavior
Successful deployment
### Current Behavior
Indeterminate `Invalid request provided: The target group with targetGroupArn does not have an associated load balancer.`
### Reproduction Steps
1. Deploy an ALB with `ecs_patterns.ApplicationLoadBalancedFargateService` with `protocol=lb.ApplicationProtocol.HTTP`,
2. Use this [workaround](https://github.com/aws/aws-cdk/issues/5583#issuecomment-2825719363) to redirect `HTTP` to `HTTPS`and deploy
3. Deploy a few times...
4. Maybe experience error?
### Possible Solution
_No response_
### Additional Information/Context
```json
"userAgent": "cloudformation.amazonaws.com",
"errorCode": "InvalidParameterException",
"errorMessage": "The target group with /CoreSt-WebAp-OBAY5UVSDTFW/5f79f6f39969fa92 does not have an associated load balancer.",
"requestParameters": {
"capacityProviderStrategy": [
{
"capacityProvider": "FARGATE",
"weight": 1,
"base": 1
}
],
"cluster": "CoreStackDev-WebAppSvcFlaskAppServiceControlPlaneEcsClusterSvcEcsClusterEcsClusterSvcB291F355-xtUAqFpdBbkj",
"deploymentConfiguration": {
"deploymentCircuitBreaker": {
"enable": true,
"rollback": true
},
"maximumPercent": 200,
"minimumHealthyPercent": 100,
"alarms": {
"rollback": false,
"enable": false
}
},
"desiredCount": 1,
"enableECSManagedTags": true,
"enableExecuteCommand": true,
"availabilityZoneRebalancing": "DISABLED",
"forceNewDeployment": false,
"healthCheckGracePeriodSeconds": 60,
"loadBalancers": [
{
"targetGroupArn": "/CoreSt-WebAp-OBAY5UVSDTFW/5f79f6f39969fa92",
"containerName": "EcsTaskDefContainerSvcEcsContainerDef",
"containerPort": 80
},
{
"targetGroupArn": "/CoreSt-WebAp-XB77YZBVGDH8/559a5660e756f528",
"containerName": "EcsTaskDefContainerSvcEcsContainerDef",
"containerPort": 80
}
],
```
### CDK CLI Version
2.180.0
### Framework Version
_No response_
### Node.js Version
v22.12.0
### OS
Mac
### Language
Python
### Language Version
_No response_
### Other information
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.