Fixing the Unauthenticated error
Issue description
When trying to access Managed Service for YDB from a local machine, you get the Unauthenticated error.
Solution
You can get authenticated using an IAM token or a service account token. You can see some code examples here
Example of using YDB Python SDK
-
Create a folder, e.g.,
ydb, and navigate to it via PowerShell or Bash:cd ydb. You will be running all subsequent commands in the terminal from this folder. -
Create an authorized key for the service account:
yc iam key create --service-account-id <id_CA> --output token.json. You will get thetoken.jsonkey in theydbfolder. -
Check the key:
ydb --endpoint grpcs://ydb.serverless.yandexcloud.net:2135 --database /ru-central1/b1gb4.../etn0fu... --sa-key-file token.json discovery whoami. You should getUser SID: ajei6s...@asin response. This means the connection has been established. -
Clone the example from GitHub:
git clone https://github.com/ydb-platform/ydb-python-sdk.git. It will be saved in the currentydbfolder for your convenience. -
Install the
python -m pip install iso8601library. -
Add the location of this file to the
YDB_SERVICE_ACCOUNT_KEY_FILE_CREDENTIALSenvironment variable:- Linux:
export YDB_SERVICE_ACCOUNT_KEY_FILE_CREDENTIALS=~/ydb/token.json - Microsoft Windows®:
$YDB_SERVICE_ACCOUNT_KEY_FILE_CREDENTIALS="C:\Users\<user>\ydb\token.json".
- Linux:
-
Run the script:
python ydb-python-sdk/examples/basic_example_v1/ -e grpcs://ydb.serverless.yandexcloud.net:2135 -d /ru-central1/b1gb4.../etn0fu....