Create an AWS Java SDK connection
Example: Create an AWS Java SDK Connection Using the Default Credentials
Use default credentials using the first credentials found in this order of precedence:
1. Environment Variables
2. System Properties
3. Default Profile in ~/.aws/credentials
The AWS Java SDK automatically reads the Access Key ID and Secret Access Key from one
of these locations. They do not need to be provided explicitly.
AmazonS3 s3Client = new AmazonS3Client();
s3Client.setEndpoint("https://systemname.example.com");
Example: Create an AWS Java SDK Connection Specifying Credentials
Provided as Strings in Code
BasicAWSCredentials credentials = new BasicAWSCredentials( 1
"ACCESS_KEY", 2
"SECRET_KEY" 3
);
AmazonS3 s3Client = new AmazonS3Client(credentials); 4
s3Client.setEndpoint("https://systemname.example.com"); 5
1 Declare a new set of basic credentials that…
2 Include the AWS Access Key ID.
3 Include the Secret Access Key.
4 Create a constructor for an S3-compatible client using the declared credentials.
5 Set the endpoint for the new S3 compatible system to 'https://systemname.example.com'.
Example: Use an AWSCredentials.properties file on the classpath
Credentials are loaded from the AWSCredentials.properties File
ClasspathPropertiesFileCredentialsProvider provider = new
ClasspathPropertiesFileCredentialsProvider(); 1
AmazonS3 s3Client = new AmazonS3Client(provider); 2
s3Client.setEndpoint("https://systemname.example.com"); 3
1 Declare a new set of basic credentials that use the AWSCredentials.properties file.
2 Create a constructor for an S3 compatible client using the credentials from the
AWSCredentials.properties file.
3 Set the endpoint for the new S3 compatible client to 'https://systemname.example.com'.
Note: The remaining examples assume the use of default credentials.