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, review the list of supported operations.
- s3: Additional commands that make it easier to work with a large number of objects.
Before you start
Installation
To install the AWS CLI, follow the instructions on the manufacturer's website.
Configuration
To configure the AWS CLI, use the aws configure
command. The command requests values for the following parameters:
-
AWS Access Key ID
: Enter the ID of the key that you received when generating the static key. -
AWS Secret Access Key
: Enter the secret key that you received when generating the static key. -
Default region name
: Enterru-central1
.Note
To work with Yandex Object Storage, always specify the
ru-central1
region. A different region value may lead to an authorization error. -
Leave the other parameter values unchanged.
Configuration files
The aws configure
command saves 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=ru-central1
Specifics
When using the AWS CLI to work with Object Storage, keep the following in mind:
-
The AWS CLI treats Object Storage like a hierarchical file system and object keys look like file paths.
-
When running the
aws
command to work with Object Storage, the--endpoint-url
parameter is required because the client is configured to work with the 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
Note
To enable debug output in the console, use the --debug
key.
Creating a bucket
aws --endpoint-url=https://storage.yandexcloud.net s3 mb s3://bucket-name
Note
When creating a bucket, follow the naming conventions.
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
Retrieving an object
aws --endpoint-url=https://storage.yandexcloud.net \
s3 cp s3://bucket-name/textfile.txt textfile.txt