aws / aws/aws-cdk

(ecs): (Ecs Service now Depends on Task Definition forcing Update to Existing Services)

Open
#25,777 10 comments 1 reaction 0 assignees View on GitHub
@aws-cdk/aws-ecs bug effort/medium p2
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
1d 19h
Merged PRs (30d)
71

Description

### Describe the bug

I'm upgrading from CDK version `2.25.0` to `2.81.0`. With no other changes on the stack aside from the upgrade, I'm getting an error in Cloudformation:

```
Resource handler returned message: "Invalid request provided: UpdateService error: Unable to update task definition on services with a CODE_DEPLOY deployment controller. Use AWS CodeDeploy to trigger a new deployment. (Service: AmazonECS; Status Code: 400; Error Code: InvalidParameterException; Request ID: xxxxxxxxx Proxy: null)" (RequestToken: XXXXXXXXXX, HandlerErrorCode: InvalidRequest)
```

I have compared the template from the Cloudformation and the local template built using the upgraded version and I can see the addition of the task definition in the DependsOn.

```
"DependsOn": [
"ApiLoadBalancerBlueTargetListenerTargetBlueRule1180D001",
"ApiTaskDefinition51EA709E"
],
```

I have narrowed down which version this was introduced. It seems to occur since version `2.50.0`. I believe this line in particular was causing the fargate service to update. However, as I'm using `DeploymentControllerType.CODE_DEPLOY` this causes the above error for already created services.

https://github.com/aws/aws-cdk/pull/22295/files#diff-becce6466790cd3cc81807ab64dd5f4ef85eed0285509d1ae43b381f24aefddaR469

### Expected Behavior

Dependencies are not added if not required.

### Current Behavior

Task definition is added as dependency on the fargate service forcing updates on existing resources.

### Reproduction Steps

# Build and deploy using v2.25.0

```
const fargateService = new FargateService(this, 'ApiFargateService', {
assignPublicIp: false,
cluster: fargateCluster,
deploymentController: {
type: DeploymentControllerType.CODE_DEPLOY
},
capacityProviderStrategies: [{
capacityProvider: 'FARGATE_SPOT',
base: 1,
weight: 100
}],
desiredCount: 0,
healthCheckGracePeriod: Duration.seconds(10),
maxHealthyPercent: 200,
minHealthyPercent: 100,
platformVersion: FargatePlatformVersion.LATEST,
securityGroups: [fargateTaskSecurityGroup],
serviceName: 'my-service',
taskDefinition: ecsTaskDefinition,
})
```

# Build and deploy using 2.50.0

### Possible Solution

If not required, can we remove the task definition from the list of the fargate service dependencies?

### Additional Information/Context

_No response_

### CDK CLI Version

2.50.0

### Framework Version

_No response_

### Node.js Version

v16.20.0

### OS

Ubuntu 20.04.5 LTS (WSL)

### Language

Typescript

### Language Version

Typescript ~4.6.4

### Other information

_No response_

Contributor guide

Open the contributing guide

Research direction

Start with the linked PR #22295 diff at the referenced line, then reproduce the issue with the TypeScript FargateService example and compare the CloudFormation templates from CDK 2.25.0 and 2.50.0. Done means a CODE_DEPLOY service does not receive an unnecessary task-definition dependency or an update to an existing service.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, typescript
Domain
cloud, infrastructure
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.