-
Notifications
You must be signed in to change notification settings - Fork 4.2k
(aws-ecs-patterns): support AvailabilityZoneRebalancing #34442
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
Comments
Hey @MorelSerge, thank you for reaching out. I believe you are referring to this announcement. The Current ImplementationThe underlying // In packages/aws-cdk-lib/aws-ecs/lib/fargate/fargate-service.ts
export interface FargateServiceProps extends BaseServiceOptions {
// ... other props
/**
* Whether to use Availability Zone rebalancing for the service.
*
* @default AvailabilityZoneRebalancing.DISABLED
*/
readonly availabilityZoneRebalancing?: AvailabilityZoneRebalancing;
} WorkaroundOn a quick test, it does appear users can access the underlying // Create the service pattern
const fargateService = new ApplicationLoadBalancedFargateService(/* props */);
// Access the CloudFormation resource of the underlying service
const cfnService = fargateService.service.node.defaultChild as CfnService;
// Set the availability zone rebalancing property
cfnService.availabilityZoneRebalancing = 'ENABLED'; ImplementationOf the top the implementation approach could be:
First, we would modify // packages/aws-cdk-lib/aws-ecs-patterns/lib/base/fargate-service-base.ts
import { FargatePlatformVersion, FargateTaskDefinition, RuntimePlatform, AvailabilityZoneRebalancing } from '../../../aws-ecs';
export interface FargateServiceBaseProps {
/**
* The task definition to use for tasks in the service. TaskDefinition or TaskImageOptions must be specified, but not both.
*
* [disable-awslint:ref-via-interface]
*
* @default - none
*/
readonly taskDefinition?: FargateTaskDefinition;
// ... existing properties ...
/**
* Whether to use Availability Zone rebalancing for the service.
*
* If enabled, `maxHealthyPercent` must be greater than 100, and the service must not be a target
* of a Classic Load Balancer.
*
* @see https://docs.aws.amazon.com/AmazonECS/latest/developerguide/service-rebalancing.html
* @default AvailabilityZoneRebalancing.DISABLED
*/
readonly availabilityZoneRebalancing?: AvailabilityZoneRebalancing;
}
Then modify // packages/aws-cdk-lib/aws-ecs-patterns/lib/fargate/application-load-balanced-fargate-service.ts
constructor(scope: Construct, id: string, props: ApplicationLoadBalancedFargateServiceProps = {}) {
super(scope, id, props);
this.assignPublicIp = props.assignPublicIp ?? false;
// ... existing code ...
const desiredCount = FeatureFlags.of(this).isEnabled(cxapi.ECS_REMOVE_DEFAULT_DESIRED_COUNT) ? this.internalDesiredCount : this.desiredCount;
this.service = new FargateService(this, 'Service', {
cluster: this.cluster,
desiredCount: desiredCount,
taskDefinition: this.taskDefinition,
assignPublicIp: this.assignPublicIp,
serviceName: props.serviceName,
healthCheckGracePeriod: props.healthCheckGracePeriod,
minHealthyPercent: props.minHealthyPercent,
maxHealthyPercent: props.maxHealthyPercent,
propagateTags: props.propagateTags,
enableECSManagedTags: props.enableECSManagedTags,
cloudMapOptions: props.cloudMapOptions,
platformVersion: props.platformVersion,
deploymentController: props.deploymentController,
circuitBreaker: props.circuitBreaker,
securityGroups: props.securityGroups,
vpcSubnets: props.taskSubnets,
enableExecuteCommand: props.enableExecuteCommand,
capacityProviderStrategies: props.capacityProviderStrategies,
availabilityZoneRebalancing: props.availabilityZoneRebalancing, // Pass through the property
});
this.addServiceAsTarget(this.service);
} Similar changes may need to be made to other ECS patterns that create Fargate services, like:
Marking this as P2 feature request. We'll leave this issue open to track the request. Meanwhile, welcome to add 👍 to help us prioritize. |
Describe the feature
The current ecs patterns, such as
ApplicationLoadBalancedFargateService
, have their rebalancing set to the default, which is disabled. It cannot be updated on theFargateService
itself.Use Case
AWS just spread an email around, saying that new ECS services will automatically have this set to enabled. It'd be good that we can also enable this for existing services, or explicitly disable for new ones if that's not desired.
Proposed Solution
No response
Other Information
No response
Acknowledgements
AWS CDK Library version (aws-cdk-lib)
2.187.0
AWS CDK CLI version
2.1003.0
Environment details (OS name and version, etc.)
MacOS 14
The text was updated successfully, but these errors were encountered: