AWS Command Line Interface (AWS CLI)

AWS CLI is a command line interface designed for AWS services. To learn how to run commands, see the official Amazon documentation.

To work with Yandex Object Storage via the AWS CLI, you can use the following sets of commands:

  • s3api — commands corresponding to operations in the REST API. Before you start, look through the list of supported operations.
  • s3 — additional commands that make it easier to work with a large number of objects.

Before you start

  1. Create a service account.
  2. Get the necessary roles.
  3. Get a static key.

Installation

To install the AWS CLI, follow the instructions on the manufacturer's website.

Setup

To configure the AWS CLI, use the aws configure command. The command will request values for the following parameters:

  1. AWS Access Key ID: enter the ID of the key that you received when generating the static key.

  2. AWS Secret Access Key: enter the secret key that you received when generating the static key.

  3. Default region name: enter 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.

  4. Leave the other parameter values unchanged.

Configuration files

The aws configure command will result in saving your settings to the following files:

  • Your static key to the .aws/credentials file in the format:

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

    [default]
                region=us-east-1
    

Specifics

When using the AWS CLI to work with Object Storage, keep the following in mind:

  • The AWS CLI works with Object Storage like a hierarchical file system and object keys look like a file path.

  • When running the aws command to work with Object Storage, the --endpoint-url parameter is required because the client is configured to work with Amazon servers by default.

  • When using macOS, in some cases you need to run the command:

    export PYTHONPATH=/Library/Python/2.7/site-packages; aws --endpoint-url=https://storage.yandexcloud.net s3 ls
    

Examples of operations

Creating a bucket

aws --endpoint-url=https://storage.yandexcloud.net s3 mb s3://bucket-name

Note

When creating a bucket, follow the naming guidelines.

Uploading objects

You can upload objects using one of the following methods:

  • Upload all objects from a local directory:

    aws --endpoint-url=https://storage.yandexcloud.net \
        s3 cp --recursive local_files/ s3://bucket-name/path_style_prefix/
    
  • Upload objects specified in the --include filter and skip objects specified in the --exclude filter:

    aws --endpoint-url=https://storage.yandexcloud.net \
        s3 cp --recursive --exclude "*" --include "*.log" \
        local_files/ s3://bucket-name/path_style_prefix/
    
  • Upload objects one by one, running the following command for each object:

    aws --endpoint-url=https://storage.yandexcloud.net \
        s3 cp testfile.txt s3://bucket-name/path_style_prefix/textfile.txt
    

Getting a list of objects

aws --endpoint-url=https://storage.yandexcloud.net \
    s3 ls --recursive s3://bucket-name

Deleting objects

You can delete objects using one of the following methods:

  • Delete all objects with the specified prefix:

    aws --endpoint-url=https://storage.yandexcloud.net \
        s3 rm s3://bucket-name/path_style_prefix/ --recursive 
    
  • Delete objects specified in the --include filter and skip objects specified in the --exclude filter:

    aws --endpoint-url=https://storage.yandexcloud.net \
        s3 rm s3://bucket-name/path_style_prefix/ --recursive \
        --exclude "*" --include "*.log"
    
  • Delete objects one by one, running the following command for each object:

    aws --endpoint-url=https://storage.yandexcloud.net \
        s3 rm s3://bucket-name/path_style_prefix/textfile.txt
    

Getting an object

aws --endpoint-url=https://storage.yandexcloud.net \
    s3 cp s3://bucket-name/textfile.txt textfile.txt