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