question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ECS Cluster.addCapacity does not set autoscalingGroup property

See original GitHub issue

When 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:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
gandrozcommented, Sep 15, 2020

My question is not really about the issue, but is kinda’ related. Is there any difference between using addCapacity or addAutoscalingGroup? I know that using addAutoscalingGroup I’ll need to create an ASG first. To me it seems that both methods do the same thing. Am I wrong?

As far as I understand it, addAutoscalingGroup adds an ASG already created to your cluster, whereas addCapacity 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.

0reactions
github-actions[bot]commented, May 13, 2021

⚠️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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

interface AddCapacityOptions · AWS CDK
The properties for adding instance capacity to an AutoScalingGroup. Example. declare const vpc: ec2.Vpc; // Create an ECS cluster const cluster = new...
Read more >
@aws-cdk/aws-ecs - npm
To use tasks with Amazon EC2 launch-type, you have to add capacity to the cluster in order for tasks to be scheduled on...
Read more >
Cluster scaling group instantly desires 2 instances without any ...
I have ECS cluster, which already uses fargate as capacity provider. ... which should not even be possible, because I set the maximum...
Read more >
Auto scaling template snippets - Amazon CloudFormation
Use these sample templates to help you create Amazon EC2 Auto Scaling and ... added to the launch template's user data (not shown)...
Read more >
aws-cdk/aws-ecs/README.md - UNPKG
129, cluster.addAutoScalingGroup(autoScalingGroup);. 130, ```. 131. 132, If you omit the property `vpc`, the construct will create a new VPC with two AZs.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found