|
| 1 | +# YDB Sdk ADO.NET for Serverless Containers in Yandex Cloud |
| 2 | + |
| 3 | +Sample application uses the YDB SDK for ADO.NET and can be deployed |
| 4 | +to [Yandex Cloud Serverless Containers](https://yandex.cloud/en/docs/serverless-containers/). |
| 5 | + |
| 6 | +## Getting started |
| 7 | + |
| 8 | +1. **Setup |
| 9 | + ** [Yandex Container Registry](https://yandex.cloud/en/docs/container-registry/operations/registry/registry-create). |
| 10 | +2. **Build and Push Docker Image** |
| 11 | + ```bash |
| 12 | + docker build . -t cr.yandex/<container-registry-id>/ado-net-app:latest |
| 13 | + docker push cr.yandex/<container-registry-id>/ado-net-app:latest |
| 14 | + ``` |
| 15 | + Replace <container-registry-id> with your actual Container Registry ID. |
| 16 | +3. **Grant Required Permissions**. To enable your Serverless Container to access both YDB and your container image in |
| 17 | + the Container Registry, grant the following roles to your Service Account: |
| 18 | + |
| 19 | + - `ydb.editor` — access to YDB, |
| 20 | + - `container-registry.images.puller` — permission to pull images from Container Registry. |
| 21 | + |
| 22 | +4. **Create a new revision**. After pushing your image, create a new version of the Serverless Container as described in |
| 23 | + the [official guide](https://yandex.cloud/en/docs/serverless-containers/quickstart/container#create-revision). |
| 24 | + Specify your image and the necessary environment variables and secrets. |
| 25 | +5. **Running the Yandex Serverless Container**. |
| 26 | + After the new revision has been rolled out, you can use your container (e.g., for a health check) by executing the following command: |
| 27 | + ```bash |
| 28 | + curl --header "Authorization: Bearer $(yc iam create-token)" https://<serverless-container-host>/ |
| 29 | + ``` |
| 30 | + Replace <serverless-container-host> with your actual serverless container host. |
| 31 | + |
| 32 | +## ⚠️ Important Note: YdbDataSource and Connection Handling |
| 33 | + |
| 34 | +When using the YDB SDK in a serverless container, it is always necessary to create a new YdbDataSource for each request |
| 35 | +or function invocation. |
| 36 | + |
| 37 | +This is because the network connectivity between a serverless container and external resources, such as YDB, can be |
| 38 | +interrupted or reset during execution. If you cache or reuse existing connections, you may experience failures due to |
| 39 | +stale or invalid connections. |
| 40 | + |
| 41 | +Best practice: |
| 42 | + |
| 43 | +_Create a fresh data source (or Driver for Topic API) for every request or function invocation in order to ensure |
| 44 | +reliability in the serverless environment._ |
0 commit comments