Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(ecs): Can't update FargateService with CODE_DEPLOY deploymentController #23564

Closed
sergeivalko opened this issue Jan 4, 2023 · 13 comments
Closed
Labels
@aws-cdk/aws-ecs Related to Amazon Elastic Container

Comments

@sergeivalko
Copy link

sergeivalko commented Jan 4, 2023

Describe the bug

When i update properties related to a service like desiredCount or any allowed cloudformation throws an exception

Expected Behavior

Service updated

Current Behavior

Error: Unable to update task definition on services with a CODE_DEPLOY deployment controller. Use AWS CodeDeploy to trigger a new deployment

Reproduction Steps

    const taskDefinition = new ecs.FargateTaskDefinition(
      this,
      'TaskDefinition',
      {
        family: family,
        taskRole,
        executionRole,
      }
    );

    const logGroup = logs.LogGroup.fromLogGroupName(
      this,
      'DockerLogGroup',
      'docker_logs'
    );

    taskDefinition.addContainer('ServiceContainer', {
      containerName: props.serviceName,
      portMappings: [{ containerPort: 5000, hostPort: 5000 }],
      logging: ecs.LogDrivers.awsLogs({
        streamPrefix: `${props.serviceName}-`,
        logGroup,
      }),
      image: ecs.ContainerImage.fromRegistry(props.image),
    });

    taskDefinition.applyRemovalPolicy(cdk.RemovalPolicy.RETAIN);

    // Create Service
    const service = new ecs.FargateService(this, 'Service', {
      cluster,
      deploymentController: {
        type: ecs.DeploymentControllerType.CODE_DEPLOY,
      },
      taskDefinition: taskDefinition,
      healthCheckGracePeriod: cdk.Duration.seconds(0),
      serviceName: props.serviceName,
      securityGroups: [securityGroup],
      vpcSubnets: {
        subnets: subnets.map((value, index) =>
          ec2.Subnet.fromSubnetId(this, `Subnet${index + 1}`, value)
        ),
      },
      ...props.service,
    });

Possible Solution

Modify request UpdateService

Additional Information/Context

I found the Update Service event and it looks like the cloudformation also sent other information like taskDefinition, network, etc in the requestParameters and I think that's not correct.
image

cdk diff:
image

CDK CLI Version

2.59.0

Framework Version

No response

Node.js Version

v14.18.0

OS

Windows

Language

Typescript

Language Version

4.9.4

Other information

No response

@sergeivalko sergeivalko added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jan 4, 2023
@github-actions github-actions bot added the @aws-cdk/aws-ecs Related to Amazon Elastic Container label Jan 4, 2023
@sergeivalko
Copy link
Author

@cplee @clareliguori Any ideas?

@sergeivalko sergeivalko changed the title (ecs): (Can't update FargateService) (ecs): Can't update FargateService Jan 4, 2023
@cplee
Copy link
Contributor

cplee commented Jan 4, 2023

@sergeivalko What does the CloudFormation changeset look like for the ECS service?

@sergeivalko
Copy link
Author

@cplee

[
  {
    "resourceChange": {
      "logicalResourceId": "DeploymentGroup6D277AF0",
      "action": "Modify",
      "physicalResourceId": "default",
      "resourceType": "AWS::CodeDeploy::DeploymentGroup",
      "replacement": "False",
      "moduleInfo": null,
      "details": [
        {
          "target": {
            "name": "ECSServices",
            "requiresRecreation": "Never",
            "attribute": "Properties"
          },
          "causingEntity": "ServiceD69D759B.Name",
          "evaluation": "Dynamic",
          "changeSource": "ResourceAttribute"
        }
      ],
      "changeSetId": null,
      "scope": [
        "Properties"
      ]
    },
    "hookInvocationCount": null,
    "type": "Resource"
  },
  {
    "resourceChange": {
      "logicalResourceId": "ServiceD69D759B",
      "action": "Modify",
      "physicalResourceId": "[ARN]-service/n2p-uniteplatform-dev/n2p-unite-call-queue-metrics-service",
      "resourceType": "AWS::ECS::Service",
      "replacement": "False",
      "moduleInfo": null,
      "details": [
        {
          "target": {
            "name": "DesiredCount",
            "requiresRecreation": "Never",
            "attribute": "Properties"
          },
          "causingEntity": null,
          "evaluation": "Static",
          "changeSource": "DirectModification"
        }
      ],
      "changeSetId": null,
      "scope": [
        "Properties"
      ]
    },
    "hookInvocationCount": null,
    "type": "Resource"
  },
  {
    "resourceChange": {
      "logicalResourceId": "ServiceTaskCountTarget23E25614",
      "action": "Modify",
      "physicalResourceId": "service/n2p-uniteplatform-dev/n2p-unite-call-queue-metrics-service|ecs:service:DesiredCount|ecs",
      "resourceType": "AWS::ApplicationAutoScaling::ScalableTarget",
      "replacement": "Conditional",
      "moduleInfo": null,
      "details": [
        {
          "target": {
            "name": "ResourceId",
            "requiresRecreation": "Always",
            "attribute": "Properties"
          },
          "causingEntity": "ServiceD69D759B.Name",
          "evaluation": "Dynamic",
          "changeSource": "ResourceAttribute"
        }
      ],
      "changeSetId": null,
      "scope": [
        "Properties"
      ]
    },
    "hookInvocationCount": null,
    "type": "Resource"
  }
]

@sergeivalko
Copy link
Author

@cplee Did you manage to reproduce?

@pahud
Copy link
Contributor

pahud commented Feb 16, 2023

Does it only happen when you specify the deploymentController prop?

deploymentController: {
        type: ecs.DeploymentControllerType.CODE_DEPLOY,
      },

@pahud pahud added the investigating This issue is being investigated and/or work is in progress to resolve the issue. label Feb 16, 2023
@pahud pahud self-assigned this Feb 16, 2023
@pahud pahud removed the needs-triage This issue or PR still needs to be triaged. label Feb 16, 2023
@sergeivalko
Copy link
Author

@pahud i'll check and let you know.

@sergeivalko
Copy link
Author

@pahud yes, it only happens when i specify deploymentController prop as CODE_DEPLOY

@clareliguori
Copy link
Member

Hello @sergeivalko, please open an issue in the CloudFormation coverage roadmap - this is an issue with the way that CloudFormation handles ECS service updates, not an issue with CDK. As you stated, the CloudFormation handler always fills in all parameters in the ECS UpdateService API call, regardless of whether those values have changed in the current changeset. When the CODE_DEPLOY deployment controller is used, ECS UpdateService API calls will be rejected if the network configuration, platform version, task definition, or load balancer is provided in the call.

@sergeivalko
Copy link
Author

@pahud
Copy link
Contributor

pahud commented Feb 23, 2023

Thank you @clareliguori for clarifying. I am closing this now as it is not relevant to CDK. Feel free to re-open if necessary.

@pahud pahud closed this as completed Feb 23, 2023
@pahud pahud removed the investigating This issue is being investigated and/or work is in progress to resolve the issue. label Feb 23, 2023
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

@pahud pahud removed their assignment Feb 23, 2023
@pahud pahud removed the bug This issue is a bug. label Feb 23, 2023
@pahud pahud changed the title (ecs): Can't update FargateService (ecs): Can't update FargateService with CODE_DEPLOY deploymentController Feb 23, 2023
@ankit-agrawal-berlin
Copy link

Does anyone has a workaround?

@nicoalonsop
Copy link

@ankit-agrawal-berlin Still happening to me and the issue was created on CloudFormation coverage roadmap #1529 6 months ago as @clareliguori suggested, but it was closed 2 months ago by a bot, and last week was reopened without any comment from AWS at all.

@clareliguori Is it possible for you to tag someone from AWS on that issue? I would love to see some updates if possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-ecs Related to Amazon Elastic Container
Projects
None yet
Development

No branches or pull requests

6 participants