[ecs] unable to specify update policy when adding ASG capacity to ECS cluster
The following code forces the updateType prop when constructing the subsequent ASG cluster:
https://github.com/aws/aws-cdk/blob/0b058f372a41092a383706dc35e32e0573b962fe/packages/%40aws-cdk/aws-ecs/lib/cluster.ts#L203
The updateType prop is of type UpdateType which is now deprecated in favor of passing an UpdatePolicy but the two arguments are mutually exclusive. If you try to pass an updatePolcy prop into this function, the following error is output:
Error: Cannot set 'signals'/'updatePolicy' and 'updateType' together. Prefer 'signals'/'updatePolicy'
The only way for callers to override the default is to supply an updateType prop to override the Cluster's default behavior when using .addCapacity(...). This means the caller must use a deprecated API which is not ideal and causes linter warnings unless they are dismissed/disabled.
I believe this could be fixed by making this wrapper method aware of the mutually-exclusive props and if neither is specified, pass updatePolicy: UpdatePolicy.rollingUpdate().
If you came here from google, this would work:
this.cluster.addCapacity("AppCap", {
...
updateType: undefined,
updatePolicy: autoscaling.UpdatePolicy.rollingUpdate(),
});
What is the equivalent to "undefined" in Python CDK? Because setting to "None" does not work, it still prints out the error. And, I agree with @jusiskin about using a Deprecated feature, it is not best practice.
update_type=None,
update_policy=autoscaling.UpdatePolicy.rolling_update(
still results in...
jsii.errors.JSIIError: Cannot set 'signals'/'updatePolicy' and 'updateType' together. Prefer 'signals'/'updatePolicy'
Subprocess exited with error 1
My solution for python CDK:
auto_scaling_group = cluster.add_capacity(...)
cfn_asg_resource = auto_scaling_group.node.default_child
cfn_asg_resource.add_override(
path="UpdatePolicy",
value={
"AutoScalingRollingUpdate": {
"MinInstancesInService": "2",
"MaxBatchSize": "1",
"PauseTime": "PT10M0S",
"WaitOnResourceSignals": "false",
"SuspendProcesses": [
"HealthCheck",
"ReplaceUnhealthy",
"AZRebalance",
"AlarmNotification",
"ScheduledActions"
]
}
}
)
cfn_asg_resource.add_deletion_override("UpdatePolicy.AutoScalingReplacingUpdate")
cfn_asg_resource.add_deletion_override("UpdatePolicy.AutoScalingScheduledAction")
This makes it really hard to use replacing update in python cdk - the workaround for ts doesn't seem to be as roundabout as the python one...
I see a warning in my CDK output stating:
updateType is deprecated. Use
updatePolicyinstead This API will be removed in the next major release.
The workaround already uses updatePolicy, so what happens when updateType is removed? Or is that only being removed in CDK v2.x.x? I'm using v1.137.0.
If you came here from google, this would work:
this.cluster.addCapacity("AppCap", { ... updateType: undefined, updatePolicy: autoscaling.UpdatePolicy.rollingUpdate(), });
I'm using cdk 2.15.0 and this solution no longer works because of updateType already removed from AddCapacityOptions
but the code still implement updateType under the hood in cluster.ts
with this solution my current solution that work is:
this.cluster.addCapacity("AppCap", {
...
...{ updateType: undefined },
updatePolicy: autoscaling.UpdatePolicy.rollingUpdate(),
});
use spread operator so updateType not cause error but still can works
⚠️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.