S3cmd

S3cmd is a command line tool (for Linux and Mac) designed for services that support the Amazon S3 HTTP API. The general procedure for running commands can be found in the official S3cmd documentation.

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 S3cmd, follow the instructions in the project repository.

Configuration

To configure S3cmd, use the s3cmd --configure command. The command will request values for the following parameters:

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

  2. Secret Key: Enter the secret key that you received when generating the static key.

  3. Default Region: Enter ru-central1.

    Note

    Always specify the ru-central1 region when accessing Object Storage. A different value of the region may lead to an authorization error.

  4. S3 Endpoint: Enter storage.yandexcloud.net.

  5. DNS-style bucket+hostname:port template for accessing a bucket: Enter %(bucket)s.storage.yandexcloud.net.

  6. Leave the other parameter values unchanged.

The client tries to establish a connection with Object Storage and get a list of buckets. If successful, it will return Success. Your access key and secret key worked fine :-).

The s3cmd --configure command saves the settings to a ~/.s3cfg file in the format:

[default]
access_key = id
secret_key = secretKey
bucket_location = ru-central1
host_base = storage.yandexcloud.net
host_bucket = %(bucket)s.storage.yandexcloud.net

If necessary, you can change these settings directly in the file. You can also specify settings when launching the client by using the appropriate parameters.

For the static website hosting control commands to work correctly, manually add the following parameter to the configuration file:

website_endpoint = http://%(bucket)s.website.yandexcloud.net

Specifics

Keep in mind that S3cmd treats Object Storage as a hierarchical file system and object keys look like file paths.

Examples of operations

Create a bucket

s3cmd  mb s3://bucket

Note

When creating a bucket, follow the naming conventions.

Uploading an object

s3cmd put local_file s3://bucket/object

Getting a list of objects

s3cmd ls s3://bucket

Retrieve an object

s3cmd get s3://bucket/object local_file

Deleting an object

s3cmd del s3://bucket/object