ECS Cluster.addCapacity does not set autoscalingGroup property
See original GitHub issueWhen calling the ECS Cluster.addCapacity() method it does not actually set the “autoscalingGroup” property as expected:
Reproduction Steps
// Create an ECS cluster
this.cluster = new ecs.Cluster(this, 'Cluster', {
vpc: this.vpc
});
// Add capacity to it
this.cluster.addCapacity('greeter-capacity', {
instanceType: new ec2.InstanceType('t3.xlarge'),
minCapacity: 3,
maxCapacity: 3
});
console.log(this.cluster.autoscalingGroup);
Expectation
According to the docs the expected output from the above code sample would be the construct for the autoscaling group that was created by addCapacity(): https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-ecs.Cluster.html#autoscalinggroup
However instead you just see “undefined”. This is because the getter for autoscalingGroup
property uses an internal property which is only set in one place in the constructor: https://github.com/aws/aws-cdk/blob/master/packages/%40aws-cdk/aws-ecs/lib/cluster.ts#L116
If you do not specify capacity options at constructor time and instead choose to subsequently use the addCapacity()
method then this property is never set within the addAutoscalingGroup()
method, therefore the reference to the autoscaling group is not retrievable via the getter method as expected
Workarounds
You can specify capacity options as part of the constructor to get around this issue, instead of using addCapacity()
. However, we should fix this so that addCapacity()
sets the property correctly, as expected.
Environment
- CLI Version : 1.21.0
- Framework Version: 1.21.0
This is 🐛 Bug Report
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:10 (3 by maintainers)
Top GitHub Comments
As far as I understand it,
addAutoscalingGroup
adds an ASG already created to your cluster, whereasaddCapacity
creates an ASG under the hood, attaches it to the cluster and returns it so you can edit it. You have the same behavior when you use the console, you can choose to use an existing ASG or let ECS build one for you.⚠️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.