1
1
Running this sample with the managed YDB instance in Yandex Cloud
2
- *********************************************************************************
2
+ ---
3
3
4
4
(0) Install the yc command line tool
5
5
https://cloud.yandex.ru/docs/cli/operations/install-cli
6
6
7
7
(1) Create the service account using the YC Web Console, and assign it the ydb.editor role.
8
8
Alternatively use the following shell snippet:
9
9
10
+ ``` bash
10
11
# Specify the Yandex Cloud folder and service account name
11
12
export YC_FOLDER=mzinal
12
13
export SA_NAME=ydb-sa-0
@@ -16,24 +17,33 @@ yc iam service-account create $SA_NAME
16
17
export SA_ID=` yc iam service-account get --name $SA_NAME | sed -n ' s/^id: \(.*\)$/\1/p' `
17
18
# Assign the ydb.editor role for the specified YC folder to the service account just created
18
19
yc resource-manager folder add-access-binding $YC_FOLDER --role ydb.editor --subject serviceAccount:$SA_ID
20
+ ```
19
21
20
22
(2) Generate the service account key to be used for authentication.
21
23
Note: unfortunately, right now YC Web Console does not offer a way to generate the SA key
22
24
with its Web interface.
23
25
26
+ ``` bash
24
27
yc iam key create --service-account-name $SA_NAME --output $HOME /key-ydb-sa-0.json
28
+ ```
25
29
26
30
(3) Obtain the endpoint and database path from the Web Console.
27
- Alternatively, use the following command to grab it in the shell:
31
+ Alternatively, use the following command to grab the required data in the shell:
28
32
29
- yc ydb db get --name ydb406
33
+ ``` bash
34
+ yc ydb db get --name ydb1
35
+ ```
36
+
37
+ ` ydb1 ` value in the command above is the logical name of the YDB managed database.
30
38
31
39
(4) Run the sample:
32
40
41
+ ``` bash
33
42
# Set the path to the service account key file
34
43
export YDB_SERVICE_ACCOUNT_KEY_FILE_CREDENTIALS=$HOME /key-ydb-sa-0.json
35
44
# Set the database path and its endpoint
36
45
export YDB_ENDPOINT=grpcs://ydb.serverless.yandexcloud.net:2135
37
46
export YDB_DATABASE=/ru-central1/b1gfvslmokutuvt2g019/etnvbffeqegu1ub2rg2o
38
47
# Run the script
39
48
python3 __main__.py -e $YDB_ENDPOINT -d $YDB_DATABASE
49
+ ```
0 commit comments