User guide
Set Up your AWS Credentials for Use with the
SDK for Java
To connect to any of the supported services with the SDK for Java, you must provide your AWS credentials.
The AWS SDKs and CLIs use provider chains to look for AWS credentials in a number of different places,
including system or user environment variables and local AWS configuration files.
Setting your credentials for use by the SDK for Java can be done in a number of ways, but here are the
recommended approaches:
• Set credentials in the AWS credentials profile file on your local system, located at:
• ~/.aws/credentials on Linux, OS X, or Unix
• C:\Users\USERNAME\.aws\credentials on Windows
This file should contain lines in the following format:
[default]
aws_access_key_id = your_access_key_id
aws_secret_access_key = your_secret_access_key
Substitute your own AWS credentials values for the values your_access_key_id and
your_secret_access_key.
• Set the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables.
To set these variables in Linux, OS X, or Unix, use export:
export AWS_ACCESS_KEY_ID=your_access_key_id
export AWS_SECRET_ACCESS_KEY=your_secret_access_key
To set these variables in Windows, use set:
set AWS_ACCESS_KEY_ID=your_access_key_id
set AWS_SECRET_ACCESS_KEY=your_secret_access_key
• To set credentials for an EC2 instance, you should specify an IAM role and then give your EC2 instance
access to that role as shown in Using IAM Roles for EC2 Instances (p. 30).
Once you have set your AWS credentials using one of these methods, they can be loaded automatically
by the SDK for Java by using the default credential provider chain. For complete information about how
to load and use AWS credentials in your SDK for Java applications, see Providing Credentials (p. 9).
Note
You can override the default location of the AWS credential file by setting the
AWS_CREDENTIAL_FILE environment variable. For more information, see Providing
Credentials (p. 9).
Version v1.0.0
7
AWS SDK for Java Developer Guide
Set Up your AWS Credentials for Use with the SDK for
Java