AWS SDK for Java

The AWS SDK for Java is a set of tools for developers working with AWS services.

Before you start

  1. Create a service account.
  2. Assign a role to a service account.
  3. Create a static access key.

Installation

To install the AWS SDK for JAVA, follow the instructions on the manufacturer's website.

Configuration

To configure the SDK, create configuration files in your home folder and set the following in them:

  • The static key in the file .aws/credentials:

    [default]
                aws_access_key_id = <id>
                aws_secret_access_key = <secretKey>
    
  • The default region in the file .aws/config:

    [default]
                region=ru-central1
    

    Note

    Some apps designed to work with Amazon S3 don't let you set the region, so Object Storage also accepts the value us-east-1.

Use the storage.yandexcloud.net address to access Object Storage.

Code samples

For a code sample, see aws-java-sdk/samples/AmazonS3 in the archive with the SDK distribution package.

To connect to Object Storage, replace the code in the sample:

AmazonS3 s3 = AmazonS3ClientBuilder.standard()
    .withCredentials(new AWSStaticCredentialsProvider(credentials))
    .withRegion("us-west-2")
    .build();

with

AmazonS3 s3 = AmazonS3ClientBuilder.standard()
    .withCredentials(new AWSStaticCredentialsProvider(credentials))
    .withEndpointConfiguration(
        new AmazonS3ClientBuilder.EndpointConfiguration(
            "storage.yandexcloud.net","ru-central1"
        )
    )
    .build();