JustSomeQuickGuy
JustSomeQuickGuy

Reputation: 943

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!

Upvotes: 7

Views: 9986

Answers (1)

Michael - sqlbot
Michael - sqlbot

Reputation: 179114

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

Upvotes: 5

Related Questions