aws-cdk icon indicating copy to clipboard operation
aws-cdk copied to clipboard

aws-ecs: `Cluster.fromClusterAttributes` does not properly set `autoScalingGroup`

Open cheruvian opened this issue 1 year ago • 1 comments

Describe the bug

Cluster.fromClusterAttributes does not properly set autoScalingGroup

Expected Behavior

autoScalingGroup to be set

Current Behavior

Is undefined which leads to NPEs.

Reproduction Steps

    const vpc   = new Vpc(this, 'Vpc', {});
    const cluster = Cluster.fromClusterAttributes(this, 'Cluster', {
      clusterName: 'my-cluster',
      vpc,
      securityGroups: [],
      autoscalingGroup: new AutoScalingGroup(this, 'Asg', {
        vpc,
        instanceType: InstanceType.of(InstanceClass.A1, InstanceSize.MICRO),
        machineImage: MachineImage.latestAmazonLinux2(),
      }),
    });
    cluster.autoscalingGroup!.addUserData('yum install -y aws-cli');

Possible Solution

All ClusterAttributes should get set on the ImportCluster.

Additional Information/Context

No response

CDK CLI Version

2.126.0

Framework Version

No response

Node.js Version

v20.10.0

OS

OSX

Language

TypeScript

Language Version

No response

Other information

No response

cheruvian avatar Feb 23 '24 23:02 cheruvian

Workaround for anyone interested:

    (this.cluster as any).autoscalingGroup = this.autoScalingGroup;

cheruvian avatar Feb 23 '24 23:02 cheruvian

Thanks for reporting this issue and noting the workaround! Looks like the PR linked above (https://github.com/aws/aws-cdk/pull/29244) was created to address this issue.

tim-finnigan avatar Feb 26 '24 19:02 tim-finnigan

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

github-actions[bot] avatar Feb 28 '24 19:02 github-actions[bot]