User guide

To explicitly supply credentials to an AWS client:
Instantiate a class that provides the AWSCredentials interface, such as BasicAWSCredentials, supplying
it with the AWS access key and secret key you will use for the connection.
Provide the class instance to a service client constructor that takes an AWSCredentials interface as input.
For example:
BasicAWSCredentials awsCreds = new BasicAWSCredentials(access_key_id,
secret_access_key)
AmazonS3 s3Client = new AmazonS3Client(awsCreds);
See Also
Get an AWS Account and Your AWS Credentials (p. 4)
Set up your AWS Credentials for Use with the SDK for Java (p. 6)
Using IAM Roles for EC2 Instances (p. 29)
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.
Each AWS client can be configured to use a specific endpoint by calling the setEndpoint(String
endpointUrl) method.
For example, to configure the Amazon EC2 client to use the EU (Ireland) Region, use the following code:
AmazonEC2 ec2 = new AmazonEC2(myCredentials);
ec2.setEndpoint("https://ec2.eu-west-1.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 your 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://ec2.eu-west-1.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.
Version v1.0.0
11
AWS SDK for Java Developer Guide
See Also