| « PreviousNext » | |
![]() ![]() | Did this page help you? Yes | No | Tell us about it... |
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.
Each AWS client can be configured to use a specific endpoint by calling the setEndpoint(String
method. endpointUrl)
For example, to configure the Amazon EC2 client to use the EU West region, use the following code:
AmazonEC2 ec2 = new AmazonEC2(myCredentials);
ec2.setEndpoint("https://eu-west-1.ec2.amazonaws.com");
Be aware that regions are logically isolated from each other, so for example, you won't be able to access US East resources when communicating with the EU West endpoint. If you're code accesses multiple AWS regions, we recommend that you instantiate a specific client for each region, as the following example shows.
AmazonEC2 ec2_euro = new AmazonEC2(myCredentials);
ec2_euro.setEndpoint("https://eu-west-1.ec2.amazonaws.com");
AmazonEC2 ec2_us = new AmazonEC2(myCredentials);
ec2_us.setEndpoint("https://ec2.us-east-1.amazonaws.com");
Using a specific client for each endpoint also protects against the (unfortunate) scenario in which, in a multithreaded environment, one thread sets the endpoint for a client and then later a different thread changes the endpoint for that client.
The AWS SDK for Java uses US East (N. Virginia) as the default region if you do not specify a region in your code. However, the AWS Management Console uses US West (Oregon) 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.
Go to Regions and Endpoints for the current list of regions and corresponding endpoints for all AWS services.