User guide
Loading Credentials
Once credentials have been set, you can load them using the SDK for Java default credential provider
chain.
To load credentials using the default credential provider chain
• Instantiate an AWS Service client using the default constructor. For example:
AmazonS3 s3Client = new AmazonS3Client();
• Alternately, you can specify a new DefaultAWSCredentialsProviderChain in the client's constructor.
The following line of code is effectively equivalent to the preceding example:
AmazonS3 s3Client = new AmazonS3Client(new DefaultAWSCredentialsProviderCha
in());
Specifying a Credential Provider or Provider Chain
If you want to specify a different credential provider than the default credential provider chain, you can
specify it in the client constructor.
To specify a specific credentials provider
• Provide an instance of a credentials provider or provider chain to a service client constructor that takes
an AWSCredentialsProvider interface as input. For example, to use environment credentials specifically:
AmazonS3 s3Client = new AmazonS3Client(new EnvironmentVariableCredentialsPro
vider());
For the full list of SDK for Java-supplied credential providers and provider chains, see the list of "All known
implementing classes" in the reference topic for AWSCredentialsProvider.
Tip
You can use this technique to supply credential providers or provider chains that you create, by
implementing your own credential provider that implements the AWSCredentialsProvider
interface, or by sub-classing the AWSCredentialsProviderChain class.
Explicitly Specifying Credentials
If neither the default credential chain or a specific or custom provider or provider chain works for your
code, you can set credentials explicitly by supplying them yourself.
In most cases, it's better to create your own credential provider and to use that (as shown in Specifying
a Credential Provider or Provider Chain (p. 10)), but there may be some situations in which this isn't
feasible.
Version v1.0.0
10
AWS SDK for Java Developer Guide
Specifying a Credential Provider or Provider Chain