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

# AWS SDK for .NET


The [AWS SDK for NET](https://aws.amazon.com/sdk-for-net/) is a software development kit for integration with AWS services.

## 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}

To install the AWS SDK for.NET, follow the [instructions](https://docs.aws.amazon.com/sdk-for-net/latest/developer-guide/net-dg-setup.html) on the manufacturer's website.

## 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 %}

## Features {#features}

* The AWS SDK for .NET incorrectly handles lifecycle configurations that contain no rule description (ID). Make sure to add a description to each lifecycle rule.
* To access Object Storage, e.g., when working with the `AmazonS3Config` class, use the `s3.yandexcloud.net` address.

## Code snippets {#net-sdk-examples}

To connect to Object Storage, use this code:

```csharp
AmazonS3Config configsS3 = new AmazonS3Config {
    ServiceURL = "https://s3.yandexcloud.net"
};

AmazonS3Client s3client = new AmazonS3Client(configsS3);
```

Here is an example of a .NET AWS SDK based program that, when you run it, will create a bucket, upload an object into it, delete the object, and delete the bucket:

```csharp
using Amazon.Runtime;
using Amazon.S3;
using Amazon.S3.Model;

namespace Example
{
    public static class Program
    {
        public static async Task Main()
        {
            var testBucketName = "your-unique-bucket-name";
            var uploadObjectKey = "object-key";
            AmazonS3Client s3client = null;

            try
            {
                // Configuring your S3 client
                AmazonS3Config configsS3 = new AmazonS3Config {
                    ServiceURL = "https://s3.yandexcloud.net",
                };
                s3client = new AmazonS3Client(configsS3);

                // Creating a bucket
                Console.WriteLine($"Creating bucket {testBucketName}");
                try 
                {
                    await s3client.PutBucketAsync(new PutBucketRequest
                    {
                        BucketName = testBucketName,
                        UseClientRegion = true
                    });
                    Console.WriteLine($"Bucket '{testBucketName}' created successfully.");
                }
                catch (AmazonS3Exception ex) when (ex.StatusCode == System.Net.HttpStatusCode.Conflict)
                {
                    Console.WriteLine($"Bucket '{testBucketName}' already exists. Continuing with existing bucket.");
                }

                // Uploading an object
                Console.WriteLine($"Uploading object to bucket '{testBucketName}'.");
                try
                {
                    await s3client.PutObjectAsync(new Amazon.S3.Model.PutObjectRequest
                    {
                        BucketName = testBucketName,
                        Key = uploadObjectKey,
                        ContentBody = "Hello World!"
                    });
                    Console.WriteLine("Object was uploaded successfully.");
                }
                catch (AmazonS3Exception ex)
                {
                    Console.WriteLine($"Error uploading object: {ex.Message}");
                    throw; // Re-throw to be caught by outer try-catch
                }

                // Deleting the object
                Console.WriteLine($"Deleting object with key '{uploadObjectKey}'");
                try
                {
                    await s3client.DeleteObjectAsync(new Amazon.S3.Model.DeleteObjectRequest
                    {
                        BucketName = testBucketName,
                        Key = uploadObjectKey
                    });
                    Console.WriteLine($"Object with key '{uploadObjectKey}' was deleted successfully");
                }
                catch (AmazonS3Exception ex)
                {
                    Console.WriteLine($"Error deleting object: {ex.Message}");
                    throw; // Re-throw to be caught by outer try-catch
                }
                
                // Deleting the bucket
                Console.WriteLine($"Deleting bucket with name '{testBucketName}'");
                try
                {
                    await s3client.DeleteBucketAsync(new Amazon.S3.Model.DeleteBucketRequest
                    {
                        BucketName = testBucketName
                    });
                    Console.WriteLine($"Bucket '{testBucketName}' was deleted successfully");
                }
                catch (AmazonS3Exception ex)
                {
                    Console.WriteLine($"Error deleting bucket: {ex.Message}");
                    // If you need to forcibly delete a non-empty bucket, you can add the code here
                    throw; // Re-throw to be caught by outer try-catch
                }
            }
            catch (AmazonS3Exception ex)
            {
                Console.WriteLine($"Amazon S3 Error: {ex.ErrorCode}, Message: {ex.Message}");
                Console.WriteLine($"Status code: {ex.StatusCode}, Request ID: {ex.RequestId}");
            }
            catch (AmazonServiceException ex)
            {
                Console.WriteLine($"Amazon Service Error: {ex.ErrorCode}, Message: {ex.Message}");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"General error: {ex.Message}");
                Console.WriteLine(ex.StackTrace);
            }
            finally
            {
                // Disposing of resources correctly
                s3client?.Dispose();
            }
        }
    }
}
```

## Useful links {#see-also}

* [Examples of employing AWS SDK for .NET in AWS articles](https://docs.aws.amazon.com/sdk-for-net/v3/developer-guide/csharp_code_examples.html)