Skip to content

‼️ NOTICE: (ecs-patterns) NetworkLoadBalancedFargateService and NetworkLoadBalancedEc2Service cause target group replacement #24642

@otaviomacedo

Description

@otaviomacedo

Please add your +1 👍 to let us know you have encountered this

Status: WORKAROUND ONLY

Overview

Versions 1.141.0 and 2.9.0 (released Jan 27, 2022) introduced a change in NetworkLoadBalancedFargateService and NetworkLoadBalancedEc2Service that will may the replacement of a Load Balancing TargetGroup. If you are currently running on a version of <1.141.0 or <2.9.0 and you are upgrading to a newer version of ecs-patterns, this change may cause interruption to your service for a couple of minutes. See below whether this affects you.

Since the change was released, many users have come to depend on the new behavior. There is no way for us to revert to the old behavior without additionally breaking users who are running stacks that have been deployed using a version released after January, 2022.

Therefore, we recommend that if you will be affected by this change, that you put an override in place before performing the upgrade of ecs-patterns from a version before 1.141.0/2.9.0 to a version after.

We are sorry for the disturbance this change has caused. Please know that we take breaking changes seriously and are constantly evolving our checks for them.

Am I affected?

TargetGroups used to be created with default port as 80, irrespective of the containerPort you have configured. A change was introduced that made the TargetGroup's port equal to the containerPort you configure. This leads to the resource replacement.

You are affected if the value for containerPort in your code is different from 80. For example:

const service = new NetworkLoadBalancedFargateService(stack, 'MyFargateService', {
  taskImageOptions: {
    containerPort: 8443,   // <-- you are affected if this value is different from 80
    image: ContainerImage.fromRegistry('amazon/amazon-ecs-sample'),
  }
});

In this example, the value 8443 used to be ignored (the TargetGroup would be created with port 80, which is fine because ECS will register the correct port for each container as it's registering the tasks with the load balancer), but in newer versions of ecs-patterns the value 8443 will be copied onto the TargetGroup's port.

If this property is not defined or is set to 80, your application won't be affected.

Workaround

Use an escape hatch to force the port number of the underlying CfnTargetGroup to 80, regardless of the value of containerPort:

const service = new NetworkLoadBalancedFargateService(stack, 'MyFargateService', {
  taskImageOptions: {
    containerPort: 8443,
    image: ContainerImage.fromRegistry('amazon/amazon-ecs-sample'),
  }
});

const targetGroup = service.targetGroup.node.defaultChild as CfnTargetGroup;
targetGroup.port = 80;

After you have made this change, you can safely upgrade.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions