Yandex Cloud
Search
Contact UsGet started
  • Blog
  • Pricing
  • Documentation
  • All Services
  • System Status
    • Featured
    • Infrastructure & Network
    • Data Platform
    • Containers
    • Developer tools
    • Serverless
    • Security
    • Monitoring & Resources
    • ML & AI
    • Business tools
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Customer Stories
    • Cloud credits to scale your IT product
    • Gateway to Russia
    • Cloud for Startups
    • Education and Science
    • Yandex Cloud Partner program
  • Blog
  • Pricing
  • Documentation
© 2025 Direct Cursus Technology L.L.C.
Yandex Managed Service for YDB
  • Getting started
  • Access management
  • Monitoring metrics
  • Audit Trails events
    • Introduction to YDB via Terraform
    • Getting authentication credentials
    • Installing and configuring Terraform and a provider to connect to YDB
    • Creating configuration files and connecting to YDB
    • Creating and editing parameters of a serverless database
    • Creating and editing parameters of a dedicated database
    • Creating row tables in a database
    • Creating document tables in a database
    • Creating a changefeed for a table
    • Creating secondary indexes in row tables
    • Managing YDB topic configurations
  • FAQ
  • Public materials
  1. Working with YDB via Terraform
  2. Creating document tables in a database

Creating document tables in a database

Written by
Yandex Cloud
Updated at May 29, 2024

Warning

You can only create document tables when using a Yandex Managed Service for YDB DB in serverless mode.

Yandex Managed Service for YDB document tables contain data as a set of items and are compatible with Amazon DynamoDB tables. Therefore, you can use the AWS provider for Terraform and the aws_dynamodb_table resource to create Yandex Managed Service for YDB document tables.

To create a document table using the AWS provider, you will need the following:

  • Service account with the ydb.editor role or higher.
  • Static access key.

To get started, you need to configure the AWS provider in the project file:

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 5.0"
    }
    yandex = {
      source = "yandex-cloud/yandex"
    }
  }
}

provider "aws" {
  region = "ru-central1"
  endpoints {
    dynamodb = "https://docapi.serverless.yandexcloud.net/ru-central1/<cloud_id>/<ydb_database_id>"
  }
  profile = "<profile_name>"
  skip_credentials_validation = true
  skip_metadata_api_check = true
  skip_region_validation = true
  skip_requesting_account_id = true
}

The aws provider arguments:

  • region: Resource deployment region. It is always set to ru-central1.
  • endpoints.dynamodb: Document API endpoint of the database. You can find the endpoint address in the management console: Yandex Managed Service for YDB → Overview → Connection → Document API endpoint.
  • profile: Name of the section containing aws_access_key_id (static access key ID) and aws_secret_access_key (secret key contents) in the ~/.aws/credentials file.
  • skip_credentials_validation: Skipping validation of credentials through the STS (Amazon Web Services Security Token Service) API. Token validation will be bypassed.
  • skip_metadata_api_check: Skipping Terraform authentication through the AWS Metadata API.
  • skip_region_validation: Skipping validation of the specified region name.
  • skip_requesting_account_id: Skipping the account ID request.

The specified skip_ parameters are required as they ensure the compatibility of the AWS provider's API requests to Yandex Cloud.

Then, you can specify the aws_dynamodb_table resource to create a document table:

resource "aws_dynamodb_table" "test" {
  name         = "<table_name>"
  billing_mode = "PAY_PER_REQUEST"

  hash_key  = "<attribute_name_1>"
  range_key = "<attribute_name_2>"

  attribute {
    name = "<attribute_name_1>"
    type = "<attribute_type>"
  }

  attribute {
    name = "<attribute_name_2>"
    type = "<attribute_type>"
  }
}

The aws_dynamodb_table resource arguments:

  • name: Table name. Tables can be stored in a hierarchical namespace within YDB. For example, to place a table into the my-test-doctable directory relative to the database root, specify the following path: my-test-doctable/table-name. If there is no such directory, it will be created automatically.
  • billing_mode: Billing model for read and write operations. The only supported model is PAY_PER_REQUEST.
  • hash_key: Attribute to use as the hash key. It is defined in the attribute section.
  • range_key: Attribute to use as the range (sorting) key. It is defined in the attribute section.
  • attribute: Section with nested attribute definitions. It consists of the name (attribute name) and type (attribute data type) fields: S for a string, N for a number.

The first time you run the script, you need to run the terraform init command to initialize the AWS provider. Then, you can run terraform plan and terraform apply. As a result of running these commands, a document table named as specified in the name parameter will be created.

Was the article helpful?

Previous
Creating row tables in a database
Next
Creating a changefeed for a table
© 2025 Direct Cursus Technology L.L.C.