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.

VPC Creation fails with 1.4.0

See original GitHub issue

🐛 Bug Report

What is the problem?

I am getting an error when I take one of the examples and deploy a simple VPC using CDK 1.4.0.

    "ExitusVpcexitusdevisolatedSubnet2Subnet32F7F7C1": {
      "Type": "AWS::EC2::Subnet",
      "Properties": {
        "CidrBlock": "10.0.160.0/19",
        "VpcId": {
          "Ref": "ExitusVpcD13CB330"
        },
        "AvailabilityZone": {
          "Fn::Select": [
            1,
            {
              "Fn::GetAZs": ""
            }
          ]
        },

Error is:

Template error: Subnet32F7F7C1) Template error: Fn::Select cannot select nonexistent value at index 1

Reproduction Steps

I am using the following code in Typescript.

class VPCStack extends Stack {
    vpc: Vpc;
    constructor(scope: App, id: string, props?: StackProps) {
        super(scope, id, props);
        // Network to run everything in
        this.vpc = new Vpc(this, `${appName}Vpc`, {
            cidr: "10.0.0.0/16",
            maxAzs: 2,
            natGateways: 1,
            subnetConfiguration: [
                {
                    name: `${appName.toLowerCase()}-${envName}-public`,
                    subnetType: SubnetType.PUBLIC,
                },
                {
                    name: `${appName.toLowerCase()}-${envName}-private`,
                    subnetType: SubnetType.PRIVATE,
                },
                {
                    name: `${appName.toLowerCase()}-${envName}-isolated`,
                    subnetType: SubnetType.ISOLATED,
                },
            ]
        });
    }
}

Verbose Log

  0/29 | 7:58:57 PM | CREATE_IN_PROGRESS   | AWS::CDK::Metadata                    | CDKMetadata 
  0/29 | 7:58:57 PM | CREATE_IN_PROGRESS   | AWS::EC2::InternetGateway             | ExitusVpc/IGW (ExitusVpcIGWC05543FA) 
  0/29 | 7:58:58 PM | CREATE_IN_PROGRESS   | AWS::EC2::EIP                         | ExitusVpc/exitus-dev-publicSubnet1/EIP (ExitusVpcexitusdevpublicSubnet1EIP929BF818) 
  0/29 | 7:58:58 PM | CREATE_IN_PROGRESS   | AWS::EC2::InternetGateway             | ExitusVpc/IGW (ExitusVpcIGWC05543FA) Resource creation Initiated
  0/29 | 7:58:58 PM | CREATE_IN_PROGRESS   | AWS::EC2::VPC                         | ExitusVpc (ExitusVpcD13CB330) 
  0/29 | 7:58:58 PM | CREATE_IN_PROGRESS   | AWS::EC2::EIP                         | ExitusVpc/exitus-dev-publicSubnet1/EIP (ExitusVpcexitusdevpublicSubnet1EIP929BF818) Resource creation Initiated
  0/29 | 7:58:58 PM | CREATE_IN_PROGRESS   | AWS::EC2::VPC                         | ExitusVpc (ExitusVpcD13CB330) Resource creation Initiated
Stack exitus-vpc-dev is still not stable (CREATE_IN_PROGRESS)
  0/29 | 7:58:59 PM | CREATE_IN_PROGRESS   | AWS::CDK::Metadata                    | CDKMetadata Resource creation Initiated
  1/29 | 7:58:59 PM | CREATE_COMPLETE      | AWS::CDK::Metadata                    | CDKMetadata 
Stack exitus-vpc-dev is still not stable (CREATE_IN_PROGRESS)
Stack exitus-vpc-dev is still not stable (CREATE_IN_PROGRESS)
  2/29 | 7:59:13 PM | CREATE_COMPLETE      | AWS::EC2::InternetGateway             | ExitusVpc/IGW (ExitusVpcIGWC05543FA) 
  3/29 | 7:59:13 PM | CREATE_COMPLETE      | AWS::EC2::EIP                         | ExitusVpc/exitus-dev-publicSubnet1/EIP (ExitusVpcexitusdevpublicSubnet1EIP929BF818) 
  4/29 | 7:59:15 PM | CREATE_COMPLETE      | AWS::EC2::VPC                         | ExitusVpc (ExitusVpcD13CB330) 
Stack exitus-vpc-dev is still not stable (CREATE_IN_PROGRESS)
  5/29 | 7:59:16 PM | CREATE_FAILED        | AWS::EC2::Subnet                      | ExitusVpc/exitus-dev-isolatedSubnet2/Subnet (ExitusVpcexitusdevisolatedSubnet2Subnet32F7F7C1) Template error: Fn::Select  cannot select nonexistent value at index 1
	new Subnet (/home/username/Code/somewhere/infra/node_modules/@aws-cdk/aws-ec2/lib/vpc.ts:1167:20)
	\_ new PrivateSubnet (/home/username/Code/somewhere/infra/node_modules/@aws-cdk/aws-ec2/lib/vpc.ts:1285:5)
	\_ /home/username/Code/somewhere/infra/node_modules/@aws-cdk/aws-ec2/lib/vpc.ts:1045:34

Environment

  • CDK CLI Version:
  • Module Version:
  • OS:
  • Language:

CDK: 1.4.0 Node: v12.8.0 OS: Ubuntu 19.04 Language: TypeScript

Other information

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
dstroppacommented, Aug 20, 2019

@wolfeidau Can you confirm if the Region you are deploying to has a default subnet in all the AZs?

From the docs: " […] the Fn::GetAZs function returns only Availability Zones that have a default subnet unless none of the Availability Zones has a default subnet; in that case, all Availability Zones are returned. "

0reactions
wolfeidaucommented, Aug 20, 2019

Spot on @dstroppa someone created a default VPC in our account and it has 3 subnets but only one is marked as a default subnet.

Moved to another region with a correctly configured default vpc / subnets and it works 💯

I now recall having this happen a long time a ago.

Hopefully everyone files this under FAQ, traps for the unwitting Cloudformation/CDK developer 😉

Read more comments on GitHub >

github_iconTop Results From Across the Web

ECS Fargate 1.4 Not Using VPC Endpoints - Stack Overflow
When a new server spun up, I saw a similar error, but this time for loading the image from ECR: ResourceInitializationError: unable to...
Read more >
Stopped tasks error codes - Amazon ECS - AWS Documentation
A common cause for this error is using a VPC that doesn't have DNS resolution enabled. This error only occurs if you use...
Read more >
@operator-error/pulumi-aws-vpc - npm
This is a package containing components for use with Pulumi, a tool for provisioning cloud infrastructure based on a description written with ...
Read more >
Amazon AWS - IBM Security QRadar
AWS Cloud: Multiple Console Login Failures From Different Source Ips ... AWS Cloud: An EC2 Instance Has Been Created In A Non-Standard VPC...
Read more >
AWS VPC module - Terraform Registry
By default this module will provision new Elastic IPs for the VPC's NAT Gateways. This means that when creating a new VPC, ...
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