User guide

Topics
Using the Default Credential Provider Chain (p. 10)
Specifying a Credential Provider or Provider Chain (p. 12)
Explicitly Specifying Credentials (p. 12)
See Also (p. 13)
Using the Default Credential Provider Chain
When you initialize a new service client without supplying any arguments, the SDK for Java will attempt
to find AWS credentials using the default credential provider chain implemented by the
DefaultAWSCredentialsProviderChain class. The default credential provider chain looks for credentials
in this order:
1. Environment VariablesAWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY. The SDK for Java
uses the EnvironmentVariableCredentialsProvider class to load these credentials.
2. Java System Propertiesaws.accessKeyId and aws.secretKey. The SDK for Java uses the
SystemPropertiesCredentialsProvider to load these credentials.
3. The default credential profiles file – typically located at ~/.aws/credentials (this location may
vary per platform), this credentials file is shared by many of the AWS SDKs and by the AWS CLI. The
SDK for Java uses the ProfileCredentialsProvider to load these credentials.
You can create a credentials file by using the aws configure command provided by the AWS CLI,
or you can create it by hand-editing the file with a text editor. For information about the credentials file
format, see AWS Credentials File Format (p. 11).
4. Instance profile credentials – these credentials can be used on EC2 instances, and are delivered
through the Amazon EC2 metadata service. The SDK for Java uses the
InstanceProfileCredentialsProvider to load these credentials.
Setting Credentials
AWS credentials must be set in at least one of the preceding locations in order to be used. For information
about setting credentials, visit one of the following topics:
For information about specifying credentials in the environment or in the default credential profiles file,
see Set Up your AWS Credentials for Use with the SDK for Java (p. 7).
For information about setting Java system properties, see the System Properties tutorial on the official
Java Tutorials website.
For information about how to set up and use instance profile credentials for use with your EC2 instances,
see Using IAM Roles for EC2 Instances (p. 30).
Setting an Alternate Credentials File Location
Although the SDK for Java will load AWS credentials automatically from the default credentials file location,
you can also specify the location yourself by setting the AWS_CREDENTIAL_FILE environment variable
with the full pathname to the credentials file.
This feature can be used to temporarily change the location where the SDK for Java looks for your
credentials file (by setting this variable with the command-line, for example), or you can set the environment
variable in your user or system environment to change it for the user or system-wide.
Version v1.0.0
10
AWS SDK for Java Developer Guide
Using the Default Credential Provider Chain