x-yc-apigateway-integration:cloud_ydb extension
x-yc-apigateway-integration:cloud_ydb
enables you to perform operations with document tables in a Yandex Managed Service for YDB database. For interaction with YDB, the Document API compatible with Amazon DynamoDB is used.
Supported operations
Operation | Supported parameters | What returns API Gateway in JSON format if the operation is successful |
---|---|---|
PutItem | table_name |
Element saved in the table |
GetItem | table_name key |
Element read from table |
UpdateItem | table_name key update_expression expression_attribute_values |
Element updated in the table |
DeleteItem | table_name key |
Element deleted from the table |
Scan | table_name limit exclusive_start_key |
A list of elements read from the table |
To convert the request body into an associative array with values of the AttributeValue type and place it into the Item
parameter when performing the PutItem
operation, pass it in JSON format.
If an object in JSON format emerges for the UpdateItem
operation, the AttributeUpdates set of changes will be generated and placed into the appropriate operation parameter.
Supported parameters
The table below lists the parameters specific to API Gateway API gateways. Read more about other parameters in the OpenAPI Specification 3.0.
Parameter | Type | Required | Parameter placement |
Description |
---|---|---|---|---|
action |
string |
Yes | No | Operation in progress. Possible values: PutItem , GetItem , UpdateItem , DeleteItem , or Scan . |
database |
string |
Yes | No | Relative path to the database. |
service_account_id |
string |
Yes | No | Service account ID. Used for authorization when performing a database operation. If this parameter is not specified, the value of the service_account_id top-level parameter is used. |
table_name |
string |
Yes | Yes | Name of the table with which the operation is performed. |
key |
string |
No | Yes | Primary key of the element with which the operation is performed. A set of attributes and their values in JSON format. You must specify all key attributes. Attribute values are automatically converted to objects of the AttributeValue type. Used in the GetItem, UpdateItem, and DeleteItem operations. |
update_expression |
string |
No | Yes | Expression that specifies how and which attributes must be updated. Used in the UpdateItem operation. |
expression_attribute_values |
string |
No | Yes | Alias that can be used in the update_expression expression instead of the attribute value. It must start with a colon : . Used in the UpdateItem operation. |
limit |
string |
No | Yes | Maximum number of elements read. Used in the Scan operation. |
exclusive_start_key |
string |
No | Yes | Primary key of the element which the search starts from. A set of attributes and their values in JSON format. Attribute values are automatically converted to objects of the AttributeValue type. Used in the Scan operation. |
Extension specification
Here is an example of the REST API service that enables you to create, obtain, update, and delete movie entities:
openapi: 3.0.0
info:
title: Movies API
version: 1.0.0
servers:
- url: https://d3drb9haai**********.apigw.yandexcloud.net
paths:
/movies:
get:
description: Get movies
x-yc-apigateway-integration:
type: cloud_ydb
action: Scan
database: /ru-central1/b3g1emj917**********/etn1f5fa8f**********
table_name: movie
limit: '{limit}'
exclusive_start_key: '{"id": "{from}"}'
operationId: getMovies
parameters:
- description: Identifier from which will be queried movies in ascending order
explode: true
in: query
name: from
required: true
schema:
type: string
style: form
- description: Maximum number of movies in response
explode: true
in: query
name: limit
required: false
schema:
default: 10.0
type: number
style: form
responses:
'200':
content:
application/json:
schema:
items:
$ref: '#/components/schemas/Movie'
type: array
description: Movies
default:
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
description: error
post:
description: Create movie
x-yc-apigateway-integration:
type: cloud_ydb
action: PutItem
database: /ru-central1/b1g1emj927**********/etn1f4fa4f**********
table_name: movie
operationId: createMovie
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/Movie'
description: Movie to create
required: true
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/Movie'
description: Created or updated movie
default:
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
description: error
/movies/{movieId}:
delete:
description: Delete movie by id
x-yc-apigateway-integration:
type: cloud_ydb
action: DeleteItem
database: /ru-central1/b1g1emj927**********/etn1f4fa4f**********
table_name: movie
key: '{"id": "{movieId}"}'
operationId: deleteMovieById
parameters:
- description: Identifier of movie
explode: false
in: path
name: movieId
required: true
schema:
type: string
style: simple
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/Movie'
description: Deleted movie
default:
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
description: error
get:
description: Get movie by id
x-yc-apigateway-integration:
type: cloud_ydb
action: GetItem
database: /ru-central1/b1g1emj927**********/etn1f4fa4f**********
table_name: movie
key: '{"id": "{movieId}"}'
operationId: getMovieById
parameters:
- description: Identifier of movie
explode: false
in: path
name: movieId
required: true
schema:
type: string
style: simple
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/Movie'
description: Movie
default:
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
description: error
put:
description: Update movie by id
x-yc-apigateway-integration:
type: cloud_ydb
action: UpdateItem
database: /ru-central1/b1g1emj927**********/etn1f4fa4f**********
table_name: movie
key: '{"id": "{movieId}"}'
operationId: updateMovieById
parameters:
- description: Identifier of movie
explode: false
in: path
name: movieId
required: true
schema:
type: string
style: simple
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/Movie'
description: Movie or attributes to update
required: true
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/Movie'
description: Updated movie
default:
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
description: error
components:
schemas:
Movie:
properties:
year:
type: integer
id:
type: string
title:
type: string
required:
- id
- title
- year
type: object
Error:
properties:
message:
type: string
required:
- message
type: object
x-yc-apigateway:
service_account_id: ajent55o2h**********