Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invalid Availability Zone when creating Instance

I'm attempting to create instance on us-west-1c (though I get the same error when trying 1b, or any other AZ) and I'm getting this error:

Caught Exception: Status Code: 400, AWS Service: AmazonEC2, AWS Error Code: InvalidParameterValue, AWS Error Message: Invalid availability zone: [us-west-1c]
Response Status Code: 400
Error Code: InvalidParameterValue

I can manually create the instance via the AWS console. Here is my code to create that instance:

   runInstancesRequest =
            new RunInstancesRequest().withInstanceType("m1.medium")
                .withImageId("ami-37b1b45e").withMinCount(1).withMaxCount(1)
                .withSecurityGroupIds("launch-wizard-6")
                .withKeyName("testkey");

        Placement place = new Placement();
        place.setAvailabilityZone("us-west-1c");

        runInstancesRequest.setPlacement(place);

        RunInstancesResult runInstancesResult = ec2.runInstances(runInstancesRequest);

I've looked over this a hundred times, compared to other examples I've found online but I'm unable to identify the reason for this error.

Any help would be very appreciated. Thanks!

like image 810
JustSomeQuickGuy Avatar asked Feb 26 '14 16:02

JustSomeQuickGuy


People also ask

How do you select availability zone while creating an EC2 instance?

Right-click the instance and select Create Image to make an AMI from the instance. Go to the AMI page, right-click on the new AMI and select Launch Instance. In the new instance settings, choose a specific (different) availability zone.

What happens if availability zone fails?

Similarly, if a failure in an Availability Zone causes an Amazon Aurora database to fail, a read-replica Aurora instance in an unaffected AZ can be automatically promoted to primary.


1 Answers

Each region in AWS is independent of the others, and the API endpoints are different.

It you aren't specifically configuring your code to send your request to the "us-west-1" region, then by default you're actually asking us-east-1 to create the instance in an availability zone that it's never heard of.

The AWS SDK for Java uses the US East (Northern Virginia) Region as the default region if you do not specify a region in your code.

— http://docs.aws.amazon.com/AWSSdkDocsJava/latest/DeveloperGuide/java-dg-region-selection.html

like image 117
Michael - sqlbot Avatar answered Oct 26 '22 12:10

Michael - sqlbot