I am trying to programmatically list my ec2 instances via the aws java api.
public static void main(String[] args) {
AWSCredentials awsCredentials = new BasicAWSCredentials(awsAccessKey, awsSecretKey);
AmazonEC2AsyncClient amazonEC2AsyncClient = new AmazonEC2AsyncClient(awsCredentials);
DescribeAvailabilityZonesRequest describeAvailabilityZonesRequest = new DescribeAvailabilityZonesRequest();
Future<DescribeAvailabilityZonesResult> describeAvailabilityZonesResultFuture = amazonEC2AsyncClient.describeAvailabilityZonesAsync(describeAvailabilityZonesRequest);
try {
DescribeAvailabilityZonesResult describeAvailabilityZonesResult = describeAvailabilityZonesResultFuture.get();
System.out.println(describeAvailabilityZonesResult);
} catch (Exception e) {
e.printStackTrace();
}
}
This prints something like:
{AvailabilityZones: [
{ZoneName: us-east-1a,State: available,RegionName: us-east-1,Messages: []},
{ZoneName: us-east-1b,State: available,RegionName: us-east-1,Messages: []},
{ZoneName: us-east-1c,State: available,RegionName: us-east-1,Messages: []}]}
However, I know I have instance in us-west-2. When I add that to my api query via
describeAvailabilityZonesRequest.withZoneNames("us-west-2");
I get this error
java.util.concurrent.ExecutionException: com.amazonaws.AmazonServiceException: Status Code: 400, AWS Service: AmazonEC2, AWS Request ID: 38956486-2686-4466-b9e0-45ef12395676, AWS Error Code: InvalidParameterValue,
AWS Error Message: Invalid availability zone: [us-west-2]
at java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.util.concurrent.FutureTask.get(FutureTask.java:188)
at com.pledgeling.platform.system.SystemAdmin.main(SystemAdmin.java:25)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: com.amazonaws.AmazonServiceException: Status Code: 400, AWS Service: AmazonEC2, AWS Request ID: 38956486-2686-4466-b9e0-45ef12395676, AWS Error Code: InvalidParameterValue, AWS Error Message: Invalid availability zone: [us-west-2]
at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:767)
at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:414)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:228)
at com.amazonaws.services.ec2.AmazonEC2Client.invoke(AmazonEC2Client.java:7918)
What should I do to fix this? Why are my us-west instances not showing up?