aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.33k stars 3.76k forks source link

ec2: Value (dummy1a) for parameter availabilityZone is invalid error #30582

Closed Henry01234 closed 2 days ago

Henry01234 commented 1 week ago

Status

Resolved

What is the issue?

The issue is related to how AWS CDK assigns availability zones (AvailabilityZone) during the creation of subnets. AWS CDK typically manages availability zones automatically based on the regions and availability zones available to your AWS account. However, sometimes there might be issues where AWS CDK incorrectly assigns an availability zone that is not valid or expected.

Error message

error
handler returned message: "Value (dummy1a) for parameter availabilityZone is invalid. Subnets can currently only be created in the following availability zones: us-east-1a, us-east-1b, us-east-1c, us-east-1d, us-east-1e, us-east-1f. (Service: Ec2, Status Code: 400, Request ID: d5e85ac0-9386-494c-8db5-a2ff7501f77f)" (RequestToken: 2f242e5e-1a76-b08a-1177-01e4f5af8f84, HandlerErrorCode: InvalidRequest)

What is the impact?

It makes it difficult to make use of CDK Script to provision resources on AWS

Workaround

We can use this to create the VPC And Subnet separately, so it doesn't need to assign dummy1a to the Subnet created with (SubnetConfiguration)... init { // Create VPC with no subnets initially val vpc = Vpc(this, "myVpc-01", VpcProps.builder() .cidr("10.0.0.0/16") .subnetConfiguration(emptyList()) .build())

    // Create subnets with specified availability zones
    val subnet1 = Subnet(this, "publicSubnet-01", SubnetProps.builder()
        .vpcId(vpc.vpcId)
        .availabilityZone("us-east-1a")
        .cidrBlock("10.0.0.0/18")
        .mapPublicIpOnLaunch(true)
        .build())

    val subnet2 = Subnet(this, "publicSubnet-02", SubnetProps.builder()
        .vpcId(vpc.vpcId)
        .availabilityZone("us-east-1b")
        .cidrBlock("10.0.64.0/18")
        .mapPublicIpOnLaunch(true)
        .build())
        }

Who is affected?

Devolopers, Software Engineers and Cloud Engineers

How do I resolve this?

make sure to read the Documentation properly. And check the ### Workaround I provided It worked!! https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.Subnet.html

Related issues

..

pahud commented 1 week ago

error handler returned message: "Value (dummy1a) for parameter availabilityZone is invalid. Subnets can currently only be created in the following availability zones: us-east-1a, us-east-1b, us-east-1c, us-east-1d, us-east-1e, us-east-1f. (Service: Ec2, Status Code: 400, Request ID: d5e85ac0-9386-494c-8db5-a2ff7501f77f)" (RequestToken: 2f242e5e-1a76-b08a-1177-01e4f5af8f84, HandlerErrorCode: InvalidRequest)

Can you share your CDK code snippet that returns this error?

github-actions[bot] commented 1 week ago

This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.