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.

Note

Install SDK 1.11.336 or higher.

Setup

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=us-east-1
    

    Note

    To work with Yandex Object Storage, always specify the us-east-1 region. A different value of the region may lead to an authorization error.

To access Object Storage, use the address storage.yandexcloud.net.

Code examples

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

To connect to Object Storage, the code in the example should be replaced

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","us-east-1"
        )
    )
    .build();