[Yandex Cloud documentation](../../index.md) > [Yandex Object Storage](../index.md) > [Tools](index.md) > SDK > AWS SDK for Java

# AWS SDK for Java


The [AWS SDK for Java](https://aws.amazon.com/ru/sdk-for-java/) is an Yandex Object Storage-compatible software development kit for integration with AWS services.

You will use the AWS SDK for Java to create a bucket, upload objects to it, clean up its contents, and delete it.

## Getting started {#before-you-begin}

1. [Create a service account](../../iam/operations/sa/create.md).
1. [Assign to the service account the roles](../../iam/operations/sa/assign-role-for-sa.md) required for your project, e.g., [storage.editor](../security/index.md#storage-editor) for a bucket (to work with a particular bucket) or a folder (to work with all buckets in this folder). For more information about roles, see [Access management with Yandex Identity and Access Management](../security/index.md).

          
    To work with objects in an [encrypted](../concepts/encryption.md) bucket, a user or [service account](../../iam/concepts/users/service-accounts.md) must have the following [roles for the encryption key](../../kms/operations/key-access.md) in addition to the `storage.configurer` [role](../security/index.md#storage-configurer):
    
    * `kms.keys.encrypter`: To read the key, [encrypt](../../kms/security/index.md#kms-keys-encrypter) and upload objects.
    * `kms.keys.decrypter`: To read the key, [decrypt](../../kms/security/index.md#kms-keys-decrypter) and download objects.
    * `kms.keys.encrypterDecrypter`: This role includes the `kms.keys.encrypter` and `kms.keys.decrypter` [permissions](../../kms/security/index.md#kms-keys-encrypterDecrypter).
    
    For more information, see [Key Management Service service roles](../../kms/security/index.md#service-roles).


1. [Create a static access key](../../iam/operations/authentication/manage-access-keys.md#create-access-key).

    
    As a result, you will get the static access key data. To authenticate in Object Storage, you will need the following:
    
    * `key_id`: Static access key ID
    * `secret`: Secret key
    
    Save `key_id` and `secret`: you will not be able to get the key value again.



To access the HTTP API directly, you need static key authentication, which is supported by the tools listed in [Supported tools](index.md).
  
{% note info %}

You can [disable using static keys for bucket access](../operations/buckets/disable-statickey-auth.md). Once disabled, access will be denied to all tools using this access option: the AWS CLI, SDK, and third-party applications. Access via [ephemeral keys](../security/ephemeral-keys.md), [temporary Security Token Service access keys](../security/sts.md), and [pre-signed URLs](../security/overview.md#pre-signed) will also be disabled. Only access with an [IAM token](../../iam/concepts/authorization/iam-token.md) or [anonymous access](../security/public-access.md) (if enabled) will remain.

{% endnote %}


You can use Yandex Lockbox to safely store the static key for access to Object Storage. For more information, see [Using a Yandex Lockbox secret to store a static access key](../tutorials/static-key-in-lockbox/index.md).

{% note info %}

A service account is only allowed to view a list of buckets in the folder it was created in.

A service account can perform actions with objects in buckets that are created in folders different from the service account folder. To enable this, [assign](../../iam/operations/sa/assign-role-for-sa.md) the service account [roles](../security/index.md#service-roles) for the appropriate folder or its bucket.

{% endnote %}

## Installation {#installation}

{% note warning %}

On December 31, 2025, the AWS SDK for Java version 1.x will reach end-of-support. We recommend that you migrate to the AWS SDK for Java version 2.x to keep receiving new features and security updates.

{% endnote %}

{% list tabs group=instructions %}

- AWS SDK v2.x {#sdk-v2}

    1. [Install Java](https://www.oracle.com/java/technologies/downloads/).
    1. [Install Apache Maven](https://maven.apache.org/install.html) to build your project.
    1. [Create a project](https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html#get-started-projectsetup) as described in the AWS guide.
        
        Below is the structure of the created project:
    
        ```text
        getstarted
        ├── README.md
        ├── pom.xml
        └── src
            ├── main
            │   ├── java
            │   │   └── org
            │   │       └── example
            │   │           ├── App.java
            │   │           ├── DependencyFactory.java
            │   │           └── Handler.java
            │   └── resources
            │       └── simplelogger.properties
            └── test
                └── java
                    └── org
                        └── example
                            └── HandlerTest.java
    
        10 directories, 7 files
        ```
    
    1. [Edit the project code](https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html#get-started-code) as described in the AWS guide.

- AWS SDK v1.x {#sdk-v1}
    
    To install the AWS SDK for Java v.1.x, use the [instructions](https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/setup-install.html) on the vendor's website.

{% endlist %}

## Configuration {#setup}

1. Create a directory to store the authentication data in and navigate to it: 

    For macOS and Linux:

    ```bash
    mkdir ~/.aws/
    ```

    For Windows:

    ```bash
    mkdir C:\Users\<username>\.aws\
    ```

1. In the `.aws` directory, create a file named `credentials` and copy the credentials [received earlier](#before-you-begin) into it:

    ```text
    [default]
    aws_access_key_id = <static_key_ID>
    aws_secret_access_key = <secret_key>
    ```

1. Create a file named `config` with the default region settings and copy the following information to it:

    ```text
    [default]
    region = ru-central1
    endpoint_url = https://storage.yandexcloud.net
    ```

    {% note info %}

    Some apps designed to work with Amazon S3 do not allow you to specify the region; this is why Object Storage may also accept the main AWS region value, which is the [first row in the table of regions](https://docs.aws.amazon.com/global-infrastructure/latest/regions/aws-regions.html#available-regions).

    {% endnote %}

To access Object Storage, use the `https://storage.yandexcloud.net` endpoint.

## Updating an endpoint {#adapt-code}

{% list tabs group=instructions %}

- AWS SDK v2.x {#sdk-v2}

    1. In the `/src/main/java/org/example` directory, open the `DependencyFactory.java` file and modify the `DependencyFactory` class:

        ```java
        public class DependencyFactory {
            private DependencyFactory() {}
            public static S3Client s3Client() {
                return S3Client.builder()
                .endpointOverride(URI.create("https://storage.yandexcloud.net"))
                .httpClientBuilder(ApacheHttpClient.builder())
                .build();
            }
        }
        ```

    1. [Run the code](https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html#get-started-run) as described in the AWS guide.

    See [this repository](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/javav2/example_code/s3/src/main/java/com/example/s3) for other examples of using the AWS SDK for Java.

- AWS SDK v1.x {#sdk-v1}
    
    In the `aws-java-sdk/samples/AmazonS3` directory, the SDK distribution archive contains the code you need to modify.

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

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

    with

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

    See [this repository](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/java/example_code/s3/src/main/java/aws/example/s3) for other examples of using the AWS SDK for Java.

{% endlist %}