User guide

See Also
Sign Up for Amazon Web Services and Get AWS Credentials (p. 4)
Set Up your AWS Credentials for Use with the SDK for Java (p. 7)
Using IAM Roles for EC2 Instances (p. 30)
AWS Region Selection
Regions enable you to access AWS services that reside physically in a specific geographic area. This
can be useful both for redundancy and to keep your data and applications running close to where you
and your users will access them.
Note
The AWS SDK for Java uses us-east-1 as the default region if you do not specify a region in
your code. However, the AWS Management Console uses us-west-2 as its default.Therefore,
when using the AWS Management Console in conjunction with your development, be sure to
specify the same region in both your code and the console.
Topics
Checking for Service Availability in an AWS Region (p. 13)
Choosing a Region (p. 13)
Choosing a Specific Endpoint (p. 14)
Developing Code that Accesses Multiple AWS Regions (p. 14)
Checking for Service Availability in an AWS Region
To see if a particular AWS service is available in a region, use the isServiceSupported method on the
region that you'd like to use. For example:
Region.getRegion(Regions.US_WEST_2).isServiceSupported(ServiceAbbreviations.Dy
namodb);
See the Regions class documentation to see which regions can be specified, and see ServiceAbbrevations
for the list of services that you can query.
Choosing a Region
Beginning with version 1.4 of the SDK for Java, you can specify a region name and the SDK will
automatically choose an appropriate endpoint for you. If you want to choose the endpoint yourself, see
Choosing a Specific Endpoint (p. 14).
The Region.getRegion method will retrieve a Region object, which you can use to create a new client
that is configured to use that region. For example:
AmazonEC2 ec2 = Region.getRegion(Regions.US_WEST_2).createClient(
AmazonEC2Client.class, credentials, clientConfig);
To choose a region for an existing AWS client, call the setRegion method on the client object. For example:
Version v1.0.0
13
AWS SDK for Java Developer Guide
See Also