Uploading objects into an Yandex Object Storage bucket using an ephemeral access key
Ephemeral access keys are temporary keys with a limited lifespan that provide a secure way to access Yandex Object Storage resources without having to store static keys. In this tutorial, you will learn how to create ephemeral keys and use them to create buckets and upload objects via the AWS CLI
To upload objects to an Object Storage bucket using an ephemeral access key:
- Get your cloud ready.
- Create a service account.
- Create an ephemeral access key.
- Configure the AWS CLI.
- Create a bucket.
- Upload an object to the bucket.
If you no longer need the resources you created, delete them.
Get your cloud ready
Sign up for Yandex Cloud and create a billing account:
- Navigate to the management console
and log in to Yandex Cloud or create a new account. - On the Yandex Cloud Billing
page, make sure you have a billing account linked and it has theACTIVEorTRIAL_ACTIVEstatus. If you do not have a billing account, create one and link a cloud to it.
If you have an active billing account, you can navigate to the cloud page
Learn more about clouds and folders here.
Required paid resources
The infrastructure support cost includes:
- Fee for storing data in a bucket (see Object Storage pricing).
- Fee for data operations (see Object Storage pricing).
Set up your environment
Install and configure the AWS CLI.
Create a service account
Create a service account you will use to create a bucket and upload objects. Assign it the storage.editor role for the folder.
- In the management console
, select Identity and Access Management. - Click Create service account.
- In the Name field, specify
ephemeral-sa. - Click
Add role and selectstorage.editor. - Click Create.
If you do not have the Yandex Cloud CLI installed yet, install and initialize it.
By default, the CLI uses the folder specified when creating the profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also set a different folder for any specific command using the --folder-name or --folder-id parameter.
-
Create a service account:
yc iam service-account create \ --name ephemeral-saResult:
id: ajeab0cnib1p******** folder_id: b0g12ga82bcv******** created_at: "2025-10-03T09:44:35.989446Z" name: ephemeral-sa -
Assign the
storage.editorrole for the folder to the service account:yc resource-manager folder add-access-binding <folder_name> \ --service-account-name ephemeral-sa \ --role storage.editorResult:
effective_deltas: - action: ADD access_binding: role_id: storage.editor subject: id: ajeab0cnib1p******** type: serviceAccount
- Create a service account named
ephemeral-sa. Do it by using the create REST API method for the ServiceAccount resource or the ServiceAccountService/Create gRPC API call. - Assign the
storage.editorrole for the current folder to the the service account. Do it by using the setAccessBindings REST API method for the Folder resource or the FolderService/SetAccessBindings gRPC API call.
To manage access to the bucket, your service account must have the storage.admin role.
To work with objects in an encrypted bucket, a user or service account must have the following roles for the encryption key in addition to the storage.configurer role:
kms.keys.encrypter: To read the key, encrypt and upload objects.kms.keys.decrypter: To read the key, decrypt and download objects.kms.keys.encrypterDecrypter: This role includes thekms.keys.encrypterandkms.keys.decrypterpermissions.
For more information, see Key Management Service service roles.
Create an ephemeral access key
Create an ephemeral access key for the ephemeral-sa service account.
If you do not have the Yandex Cloud CLI installed yet, install and initialize it.
By default, the CLI uses the folder specified when creating the profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also set a different folder for any specific command using the --folder-name or --folder-id parameter.
-
Get the service account ID:
yc iam service-account get --name ephemeral-sa --format json | jq -r .id -
Create an ephemeral access key:
yc iam access-key issue-ephemeral \ --subject-id <service_account_ID> \ --session-name ephemeral-key-storage \ --duration 2hWhere:
--subject-id: ID of theephemeral-saservice account you got in the previous step.--session-name: Session name.--duration: Key lifetime.
Result:
access_key_id: ajelprpohp8t******** secret: YCOs05v-KRXqhYpUINdWArH4MINhMyJ6CGU******** session_token: s1.9muilY******** expires_at: "2025-12-16T06:23:51.383485065Z" -
Save
access_key_id, thesecretkey, andsession_token.Alert
You will not be able to get these values again.
Configure the AWS CLI
Configure the AWS CLI to work with the ephemeral access key.
-
Create a new profile in the
~/.aws/credentialsfile:[ephemeral-profile] aws_access_key_id = <key_ID> aws_secret_access_key = <secret_key> aws_session_token = <session_token>In this profile, specify the values you got when creating the ephemeral key:
aws_access_key_id:access_key_idkey ID.aws_secret_access_key:secretkey.aws_session_token:session_token.
-
Configure the Object Storage endpoint for the new profile:
aws configure set endpoint_url https://storage.yandexcloud.net/ --profile ephemeral-profileNote
Instead of setting the endpoint, you can specify it when running commands using
--endpoint-url. -
Check your configuration:
aws s3 ls --profile ephemeral-profileIf the configuration is correct, the command will run without errors.
Create a bucket
Create a bucket to store objects.
Run this command with the bucket name specified:
aws s3 mb s3://<bucket_name> \
--profile ephemeral-profile
Result:
make_bucket: my-bucket
For more information, see Creating a bucket.
Upload an object to the bucket
Upload an object to the new bucket.
-
Create a test file:
echo "Hello, Yandex Cloud!" > test-file.txt -
Run the command below to upload the file, stating the path to the local file, bucket name, and key for storing the object in the bucket:
aws s3 cp test-file.txt \ s3://<bucket_name>/test-file.txt \ --profile ephemeral-profileResult:
upload: ./test-file.txt to s3://my-bucket/test-file.txt -
Make sure the object has been uploaded successfully:
aws s3 ls s3://<bucket_name>/ \ --profile ephemeral-profileResult:
2025-10-03 09:45:12 23 test-file.txt
For more information, see Uploading an object.
How to delete the resources you created
To stop paying for the resources you created:
- Delete the objects from the bucket.
- Delete the bucket.