S3cmd
S3cmd
Getting started
- Create a service account.
- Assign the service account the roles required for your project. For more information about roles, see the Identity and Access Management documentation.
- Create a static access key.
Note
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 the service account roles for the appropriate folder or its bucket.
Installing
To install S3cmd, check out the installation section
Setup
To configure S3cmd, use the s3cmd --configure
command. For a query, specify values for the following parameters:
-
Access Key
: Enter the ID of the key you received when generating the static key. -
Secret Key
: Enter the secret key you received when generating the static key. -
Set
Default Region
toru-central1
.To work with Object Storage, always specify
ru-central1
as the region. A different region value may lead to an authorization error. -
Set
S3 Endpoint
tostorage.yandexcloud.net
. -
Set
DNS-style bucket+hostname:port template for accessing a bucket
to%(bucket)s.storage.yandexcloud.net
. -
Leave the other parameter values unchanged.
The program will try to establish a connection with Object Storage and get a list of buckets. If successful, it will display Success. Your access key and secret key worked fine :-)
.
The s3cmd --configure
command will save the settings in a ~/.s3cfg
file in the following 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
Things to consider
- S3cmd treats Object Storage as a hierarchical file system and object keys look like file paths.
- By default, S3cmd uploads objects to standard storage. To specify the storage class when uploading an object, use the
--storage-class
key. - By default, when uploading an object, S3cmd can send the additional
X-Amz-Meta-S3cmd-Attrs
header with the attributes of your file (access permissions, file owners, timestamps). The header value is saved in the metadata of the object. You can disable the sending of attributes using thepreserve_attrs = False
parameter in the~/.s3cfg
configuration file or using the--no-preserve
key.
Examples of operations
Note
To enable debug output in the console, use the --debug
key.
Getting a list of buckets
Note
You can authorize in the Amazon S3 HTTP API and tools that support it using static keys obtained for the service account.
You can only view the list of buckets in the directory in which the service account you are using was created.
s3cmd ls
Create a bucket
s3cmd mb s3://bucket
When creating a bucket, follow the naming conventions.
Uploading an object to cold storage
s3cmd --storage-class COLD put local_file s3://bucket/object
Getting a list of objects
s3cmd ls s3://bucket
Retrieving an object
s3cmd get s3://bucket/object local_file
Deleting an object
s3cmd del s3://bucket/object