Skip to content
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

[ec2] Issue with selectSubnet's availability zone #10596

Closed
shreyasmm opened this issue Sep 29, 2020 · 3 comments
Closed

[ec2] Issue with selectSubnet's availability zone #10596

shreyasmm opened this issue Sep 29, 2020 · 3 comments
Assignees
Labels
@aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud guidance Question that needs advice or information. needs-triage This issue or PR still needs to be triaged. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.

Comments

@shreyasmm
Copy link

shreyasmm commented Sep 29, 2020

❓ General Issue

I am having issue with IVpc.selectSubnets, cdk packages version 1.64.1

the below code works fine when using

"@aws-cdk/aws-ec2": "1.63.0",
"@aws-cdk/core": "1.63.0",
"@aws-cdk/aws-autoscaling": "1.63.0"
// @common package's index.ts

// Initialize Empty Arrays
this.privateSubnets = [];

// Get Private Subnets
this.privateSubnetIds = cdk.Token.asList(this.vpcLookup.getAttString('privateSubnetIds'));
for (let subnet of this.privateSubnetIds) {
  this.privateSubnets.push(ec2.Subnet.fromSubnetId(this,subnet,subnet));
}
this.privateSubnetsRef = this.vpcRef.selectSubnets({
  subnets: this.privateSubnets,
})

//asg package's index.ts
this.autoScalingGroup = new asg.AutoScalingGroup(this, 'ASG', {
  associatePublicIpAddress: false,
  autoScalingGroupName: props.autoScalingGroupName,
  blockDevices: this.blockDevices,
  cooldown: props.cooldown,
  desiredCapacity: props.desiredCapacity,
  instanceType: new ec2.InstanceType(props.instanceType),
  keyName: props.keyName,
  machineImage: amiLookup.amiIdRef,
  maxCapacity: props.maxCapacity,
  minCapacity: props.minCapacity,
  role: this.role,
  securityGroup: this.securityGroup,
  vpc: vpcLookup.vpcRef,
  vpcSubnets: vpcLookup.privateSubnetsRef,
});
yarn run test
yarn run v1.22.10
$ jest --passWithNoTests
 PASS  src/__tests__/asg.test.ts
  ✓ Auto Scaling Group Created (272ms)
  ✓ Auto Scaling Group - with no Security Group Input (267ms)
  ✓ Auto Scaling Group - with no Role Input (149ms)

Test Suites: 1 passed, 1 total
Tests:       3 passed, 3 total
Snapshots:   0 total
Time:        3.748s, estimated 4s
Ran all test suites.
Done in 4.24s.

i just updated all core packages to 1.64.1

yarn run test                                          
yarn run v1.22.10
$ jest --passWithNoTests
 FAIL  src/__tests__/asg.test.ts
  ✕ Auto Scaling Group Created (70ms)
  ✕ Auto Scaling Group - with no Security Group Input (147ms)
  ✕ Auto Scaling Group - with no Role Input (34ms)

  ● Auto Scaling Group Created

    You cannot reference a Subnet's availability zone if it was not supplied. Add the availabilityZone when importing using Subnet.fromSubnetAttributes()

      286 |     // const healthCheck = new asg.HealthCheck()
      287 | 
    > 288 |     this.autoScalingGroup = new asg.AutoScalingGroup(this, 'ASG', {
          |                             ^
      289 |       associatePublicIpAddress: false,
      290 |       autoScalingGroupName: props.autoScalingGroupName,
      291 |       blockDevices: this.blockDevices,

      at ImportedSubnet.get availabilityZone [as availabilityZone] (../../node_modules/@aws-cdk/aws-ec2/lib/vpc.ts:1937:13)
      at ../../node_modules/@aws-cdk/aws-ec2/lib/vpc.ts:364:69
          at Array.map (<anonymous>)
      at Object.get availabilityZones [as availabilityZones] (../../node_modules/@aws-cdk/aws-ec2/lib/vpc.ts:364:58)
      at LookedUpVpc.reifySelectionDefaults (../../node_modules/@aws-cdk/aws-ec2/lib/vpc.ts:556:19)
      at LookedUpVpc.selectSubnetObjects (../../node_modules/@aws-cdk/aws-ec2/lib/vpc.ts:460:22)
      at LookedUpVpc.selectSubnets (../../node_modules/@aws-cdk/aws-ec2/lib/vpc.ts:359:26)
      at new AutoScalingGroup (../../node_modules/@aws-cdk/aws-autoscaling/lib/auto-scaling-group.ts:688:48)
      at new Asg (src/index.ts:288:29)
      at Object.<anonymous> (src/__tests__/asg.test.ts:14:3)

The Question

Is this the expected working or am i missing something
I tried to pass empty string and dummy values its not working

this.privateSubnetsRef = this.vpcRef.selectSubnets({
      subnets: this.privateSubnets,
      availabilityZones: []
    })

Environment

  • CDK CLI Version: 1.64.1 (build 14a8c8d)
  • Module Version: "@aws-cdk/aws-ec2": "1.64.1", "@aws-cdk/core": "1.64.1","@aws-cdk/aws-autoscaling": "1.64.1"
  • Node.js Version: v12.18.3
  • OS: Ubuntu20.04 - Pop!os 20.04
  • Language (Version): Typescript

Other information

#6607
#8301

@shreyasmm shreyasmm added guidance Question that needs advice or information. needs-triage This issue or PR still needs to be triaged. labels Sep 29, 2020
@shreyasmm shreyasmm changed the title Issue with selectsSubnet's availability zone Issue with selectSubnet's availability zone Sep 29, 2020
@SomayaB SomayaB changed the title Issue with selectSubnet's availability zone [ec2] Issue with selectSubnet's availability zone Sep 29, 2020
@github-actions github-actions bot added the @aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud label Sep 29, 2020
@rix0rrr
Copy link
Contributor

rix0rrr commented Oct 2, 2020

this.privateSubnetsRef = this.vpcRef.selectSubnets({
  subnets: this.privateSubnets,
})

// ...

  vpcSubnets: vpcLookup.privateSubnetsRef,

You're not supposed to pass the RESULT of selectSubnets but the INPUT to it:

  vpcSubnets: { subnets: this.privateSubnets },

@rix0rrr rix0rrr added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Oct 2, 2020
@shreyasmm
Copy link
Author

This solved the issue its working. thx @rix0rrr

@github-actions
Copy link

github-actions bot commented Oct 2, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud guidance Question that needs advice or information. needs-triage This issue or PR still needs to be triaged. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.
Projects
None yet
Development

No branches or pull requests

2 participants