Yandex Cloud
Search
Contact UsGet started
  • Pricing
  • Customer Stories
  • Documentation
  • Blog
  • All Services
  • System Status
    • Featured
    • Infrastructure & Network
    • Data Platform
    • Containers
    • Developer tools
    • Serverless
    • Security
    • Monitoring & Resources
    • AI for business
    • Business tools
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Start testing with double trial credits
    • Cloud credits to scale your IT product
    • Gateway to Russia
    • Cloud for Startups
    • Center for Technologies and Society
    • Yandex Cloud Partner program
  • Pricing
  • Customer Stories
  • Documentation
  • Blog
© 2025 Direct Cursus Technology L.L.C.
Yandex Object Storage
    • All tutorials
    • Getting statistics on object queries with S3 Select
    • Getting website traffic statistics with S3 Select
    • Getting statistics on object queries using Yandex Query
    • Cost analysis by resource
    • Server-side encryption
    • Integrating an L7 load balancer with CDN and Object Storage
    • Blue-green and canary deployment of service versions
    • Analyzing logs in DataLens
    • Mounting buckets to Yandex Data Processing host filesystems
    • Using Object Storage in Yandex Data Processing
    • Importing data from Object Storage, processing it, and exporting it to Managed Service for ClickHouse®
    • Connecting a bucket as a disk in Windows
    • Migrating data from Yandex Data Streams using Yandex Data Transfer
    • Using hybrid storage in Yandex Managed Service for ClickHouse®
    • Loading data from Yandex Managed Service for OpenSearch to Yandex Object Storage using Yandex Data Transfer
    • Automatically copying objects from one bucket to another
    • Regular asynchronous recognition of audio files in a bucket
    • Training a model in Yandex DataSphere on data from Object Storage
    • Connecting to Object Storage from VPC
    • Migrating data to Yandex Managed Service for PostgreSQL using Yandex Data Transfer
    • Uploading data to Yandex MPP Analytics for PostgreSQL using Yandex Data Transfer
    • Uploading data to Yandex Managed Service for ClickHouse® using Yandex Data Transfer
    • Uploading data to Yandex Managed Service for YDB using Yandex Data Transfer
    • Exchanging data between Yandex Managed Service for ClickHouse® and Yandex Data Processing
    • Uploading data from Yandex Managed Service for YDB using Yandex Data Transfer
    • Hosting a static Gatsby website in Object Storage
      • Overview
      • CLI
      • Terraform
    • Migrating a database from Managed Service for PostgreSQL to Object Storage
    • Exchanging data between Yandex Managed Service for ClickHouse® and Yandex Data Processing
    • Importing data from Yandex Managed Service for PostgreSQL to Yandex Data Processing using Sqoop
    • Importing data from Yandex Managed Service for MySQL® to Yandex Data Processing using Sqoop
    • Migrating data from Yandex Object Storage to Yandex Managed Service for MySQL® using Yandex Data Transfer
    • Migrating a database from Yandex Managed Service for MySQL® to Yandex Object Storage
    • Exporting Greenplum® data to a cold storage in Yandex Object Storage
    • Loading data from Yandex Direct to a Yandex Managed Service for ClickHouse® data mart using Yandex Cloud Functions, Yandex Object Storage, and Yandex Data Transfer
    • Uploading Terraform states to Object Storage
    • Locking Terraform states using Managed Service for YDB
    • Visualizing Yandex Query data
    • Publishing game updates
    • VM backups using Hystax Acura
    • Backing up to Object Storage with CloudBerry Desktop Backup
    • Backing up to Object Storage with Duplicati
    • Backing up to Object Storage with Bacula
    • Backing up to Object Storage with Veeam Backup
    • Backing up to Object Storage with Veritas Backup Exec
    • Managed Service for Kubernetes cluster backups in Object Storage
    • Developing a custom integration in API Gateway
    • URL shortener
    • Storing application runtime logs
    • Developing a skill for Alice and a website with authorization
    • Creating an interactive serverless application using WebSocket
    • Deploying a web application using the Java Servlet API
    • Developing a Telegram bot
    • Replicating logs to Object Storage using Fluent Bit
    • Replicating logs to Object Storage using Data Streams
    • Uploading audit logs to ArcSight SIEM
    • Uploading audit logs to Splunk SIEM
    • Creating an MLFlow server for logging experiments and artifacts
    • Operations with data using Yandex Query
    • Federated data queries using Query
    • Recognizing text in image archives using Vision OCR
    • Regular recognition of images and PDF documents from an Object Storage bucket
    • Converting a video to a GIF in Python
    • Automating tasks using Managed Service for Apache Airflow™
    • Processing files with usage details in Yandex Cloud Billing
    • Deploying a web app with JWT authorization in API Gateway and authentication in Firebase
    • Searching for Yandex Cloud events in Yandex Query
    • Searching for Yandex Cloud events in Object Storage
    • Creating an external table from a bucket table using a configuration file
    • Migrating databases from Google BigQuery to Managed Service for ClickHouse®
    • Using Object Storage in Yandex Managed Service for Apache Spark™
  • Pricing policy
  • Terraform reference
  • Monitoring metrics
  • Audit Trails events
  • Bucket logs
  • Release notes
  • FAQ

In this article:

  • Getting started
  • Required paid resources
  • Set up your environment
  • Save the static access key to the Yandex Lockbox secret
  • Use the key from the Yandex Lockbox secret for your operations with the service
  • How to delete the resources you created
  1. Tutorials
  2. Storing a static access key in a Yandex Lockbox secret
  3. CLI

Using a Yandex Lockbox secret to store a static access key via the CLI

Written by
Yandex Cloud
Updated at August 15, 2025
  • Getting started
    • Required paid resources
  • Set up your environment
  • Save the static access key to the Yandex Lockbox secret
  • Use the key from the Yandex Lockbox secret for your operations with the service
  • How to delete the resources you created

To use a static access key saved in a Yandex Lockbox secret via the CLI:

  1. Set up your environment.
  2. Save the static access key to a Yandex Lockbox secret.
  3. Use the key from the Yandex Lockbox secret for your operations with the service.

If you no longer need the resources you created, delete them.

Getting startedGetting started

Sign up for Yandex Cloud and create a billing account:

  1. Navigate to the management console and log in to Yandex Cloud or create a new account.
  2. On the Yandex Cloud Billing page, make sure you have a billing account linked and it has the ACTIVE or TRIAL_ACTIVE status. 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 to create or select a folder for your infrastructure.

Learn more about clouds and folders here.

Required paid resourcesRequired paid resources

The infrastructure support costs include:

  • Fee for storing one version of the Yandex Lockbox secret (see Yandex Lockbox pricing).
  • Fee for data storage in Object Storage, data operations, and outgoing traffic (you will not be charged unless there is data in the bucket). See Object Storage pricing.

Set up your environmentSet up your environment

  1. 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.

  2. Install the AWS CLI.

    You do not need to configure the utility at this step. The required parameters, such as IDs and access keys, will be described and used in commands and environment variables further on in this guide.

Save the static access key to the Yandex Lockbox secretSave the static access key to the Yandex Lockbox secret

Yandex Cloud CLI
  1. Create a service account, e.g., storage-bucket-sa, that you will use to perform operations in Object Storage:

    yc iam service-account create storage-bucket-sa
    

    Result:

    done (1s)
    id: ajeplujf759j********
    folder_id: b1gt6g8ht345********
    created_at: "2024-05-07T19:18:37.244159066Z"
    name: storage-bucket-sa
    

    Save the service account id, as you will need it to assign roles to the service account.

    For more information about the yc iam service-account create command, see the CLI reference.

  2. Assign the storage.editor role for the folder to the service account you created.

    yc resource-manager folder add-access-binding <folder_name_or_ID> \
      --role storage.editor \
      --subject serviceAccount:<service_account_ID>
    

    Where:

    • <folder_name_or_ID>: Name or ID of the folder where you created the service account.
    • <service_account_ID>: Service account ID you saved in the previous step.

    Result:

    done (2s)
    effective_deltas:
      - action: ADD
        access_binding:
          role_id: storage.editor
          subject:
            id: ajeplujf759j********
            type: serviceAccount
    

    For more information about the yc resource-manager folder add-access-binding command, see the CLI reference.

  3. Similarly, assign the lockbox.payloadViewer role for the folder to the service account:

    yc resource-manager folder add-access-binding <folder_name_or_ID> \
      --role lockbox.payloadViewer \
      --subject serviceAccount:<service_account_ID>
    
  4. Create a static access key for the service account. To avoid displaying the key value on the screen, it will be saved to the STATIC_KEY variable:

    STATIC_KEY=$(yc iam access-key create --service-account-name storage-bucket-sa)
    

    For more information about the yc iam access-key create command, see the CLI reference.

  5. Save the key ID and secret key values to the separate KEY_ID and KEY_VALUE variables:

    KEY_ID=$(echo | awk '{if (match($0, "key_id: ")) {print substr($0, RSTART + 8, 25)}}' <<< "$STATIC_KEY") \
      && KEY_VALUE=$(echo | awk '{if (match($0, "secret: ")) {print substr($0, RSTART + 8, 40)}}' <<< "$STATIC_KEY")
    
  6. Create a Yandex Lockbox secret named static-key containing the new static access key:

    yc lockbox secret create \
      --name static-key \
      --payload "[{'key': $KEY_ID, 'text_value': $KEY_VALUE}]" \
      --cloud-id <cloud_ID> \
      --folder-id <folder_ID> \
      --deletion-protection
    

    Where:

    • --cloud-id: ID of the cloud where you created the service account.
    • --folder-id: ID of the folder where you created the service account.
    • --deletion-protection: Secret deletion protection. You cannot delete a secret with this option enabled. This is an optional setting.

    Result:

    done (1s)
    id: e6qk0c62b4ep********
    folder_id: b1gt6g8ht345********
    created_at: "2024-05-07T20:05:51.569Z"
    name: static-key
    status: ACTIVE
    current_version:
      id: e6qrsj2hi8ug********
      secret_id: e6qk0c62b4ep********
      created_at: "2024-05-07T20:05:51.569Z"
      status: ACTIVE
      payload_entry_keys:
        - YCAJEO4w80Zf5DERM********
    deletion_protection: true
    

    For more information about the yc lockbox secret create command, see the CLI reference.

The service account's static access key is now securely held in the Yandex Lockbox secret.

Use the key from the Yandex Lockbox secret for your operations with the serviceUse the key from the Yandex Lockbox secret for your operations with the service

The example below is intended to be run in MacOS and Linux. To run it in Windows, see how to work with Bash in Microsoft Windows.

  1. Get the static access key saved in the static-key secret. To avoid displaying the key value on the screen, it will be saved to the SECRET variable:

    Yandex Cloud CLI
    SECRET=$(yc lockbox payload get <secret_name_or_ID>)
    

    Use either the --id or --name parameter.

    For more information about the yc lockbox payload get command, see the CLI reference.

  2. Save the key ID, secret key, and placement region to the AWS CLI environment variables:

    export AWS_ACCESS_KEY_ID=$(echo | awk '{if (match($0, "key: ")) {print substr($0, RSTART + 5, 25)}}' <<< "$SECRET") \
      && export AWS_SECRET_ACCESS_KEY=$(echo | awk '{if (match($0, "text_value: ")) {print substr($0, RSTART + 12, 40)}}' <<< "$SECRET") \
      && export AWS_DEFAULT_REGION="ru-central1"
    

    The AWS CLI will use the environment variables you created for authentication when performing operations with the service resources.

  3. Create a bucket in Object Storage, specifying a unique bucket name in the command:

    AWS CLI
    aws --endpoint-url=https://storage.yandexcloud.net \
      s3 mb s3://<bucket_name>
    

    Result:

    make_bucket: my-first-bucket
    

    This will create a new bucket in Object Storage. When creating a bucket, a static access key is used obtained from the Yandex Lockbox secret and saved in environment variables.

    You can also include the key ID, secret key, and placement region values directly in each AWS CLI command:

    AWS CLI
    AWS_ACCESS_KEY_ID=$(echo | awk '{if (match($0, "key: ")) {print substr($0, RSTART + 5, 25)}}' <<< "$SECRET") \
      AWS_SECRET_ACCESS_KEY=$(echo | awk '{if (match($0, "text_value: ")) {print substr($0, RSTART + 12, 40)}}' <<< "$SECRET") \
      AWS_DEFAULT_REGION="ru-central1" \
      aws --endpoint-url=https://storage.yandexcloud.net \
      s3 mb s3://<bucket_name>
    

    Result:

    make_bucket: my-first-bucket
    

How to delete the resources you createdHow to delete the resources you created

To stop using the resources you created:

  1. Delete the secret.
  2. Delete the bucket.

See alsoSee also

  • Using a Yandex Lockbox secret to store a static access key with Terraform

Was the article helpful?

Previous
Overview
Next
Terraform
© 2025 Direct Cursus Technology L.L.C.