Skip to content

Commit 9681f67

Browse files
dev: update serverless example
1 parent b63680c commit 9681f67

File tree

3 files changed

+26
-16
lines changed

3 files changed

+26
-16
lines changed

examples/Ydb.Sdk.AdoNet.Yandex.Cloud.Serverless.Container/Program.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Diagnostics;
2+
using Dapper;
23
using Microsoft.Extensions.Configuration;
34
using Microsoft.Extensions.Logging;
45
using NLog.Extensions.Logging;
@@ -18,18 +19,17 @@
1819
var stopwatch = Stopwatch.StartNew();
1920
stopwatch.Start();
2021

21-
await using var dataSource = new YdbDataSource(
22-
new YdbConnectionStringBuilder(connectionString)
23-
{
24-
CredentialsProvider = new MetadataProvider(loggerFactory: loggerFactory),
25-
LoggerFactory = loggerFactory,
26-
DisableDiscovery = true
27-
}
28-
);
22+
await using var ydbDataSource = new YdbDataSource(new YdbConnectionStringBuilder(connectionString)
23+
{
24+
CredentialsProvider = new MetadataProvider(loggerFactory: loggerFactory),
25+
LoggerFactory = loggerFactory,
26+
DisableDiscovery = true,
27+
EnableImplicitSession = true
28+
});
2929

30-
await using var ydbCommand = dataSource.CreateCommand();
31-
ydbCommand.CommandText = "SELECT 'Hello Serverless YDB from Yandex Cloud Serverless Container!'u";
32-
var scalar = await ydbCommand.ExecuteScalarAsync();
30+
await using var ydbConnection = await ydbDataSource.OpenRetryableConnectionAsync();
31+
var scalar = await ydbConnection.ExecuteScalarAsync<string>(
32+
"SELECT 'Hello Serverless YDB from Yandex Cloud Serverless Container!'u");
3333
stopwatch.Stop();
3434

3535
logger.LogInformation("Success request! [Ms: {Ms}], {Select}", stopwatch.ElapsedMilliseconds, scalar);

examples/Ydb.Sdk.AdoNet.Yandex.Cloud.Serverless.Container/README.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,32 @@ to [Yandex Cloud Serverless Containers](https://yandex.cloud/en/docs/serverless-
66
## Getting started
77

88
1. **Setup** [Yandex Container Registry](https://yandex.cloud/en/docs/container-registry/operations/registry/registry-create).
9-
2. **Build and Push Docker Image**
9+
2. **Configure YDB Connection String**. Update the `appsettings.json` file with your YDB connection details:
10+
```json
11+
{
12+
"ConnectionStrings": {
13+
"ServerlessYDB": "UseTls=true;Host=<your-ydb-host>;Port=2135;Database=<your-database-path>"
14+
}
15+
}
16+
```
17+
Replace `<your-ydb-host>` with your YDB endpoint host and `<your-database-path>` with your database path (e.g., `/ru-central1/b1g8ejbxxxxxxxx/etn8xxxxxxxx`).
18+
3. **Build and Push Docker Image**
1019
```bash
1120
docker build . -t cr.yandex/<container-registry-id>/ado-net-app:latest
1221
docker push cr.yandex/<container-registry-id>/ado-net-app:latest
1322
```
1423
Replace <container-registry-id> with your actual Container Registry ID.
15-
3. **Grant Required Permissions**. To enable your Serverless Container to access both YDB and your container image in
24+
4. **Grant Required Permissions**. To enable your Serverless Container to access both YDB and your container image in
1625
the Container Registry, grant the following roles to your Service Account:
1726

1827
- `ydb.editor` — access to YDB,
1928
- `container-registry.images.puller` — permission to pull images from Container Registry.
2029

21-
4. **Create a new revision**. After pushing your image, create a new version of the Serverless Container as described in
30+
5. **Create a new revision**. After pushing your image, create a new version of the Serverless Container as described in
2231
the [official guide](https://yandex.cloud/en/docs/serverless-containers/quickstart/container#create-revision).
2332
Specify your image and the necessary environment variables and secrets.
2433

25-
5. **Running the Yandex Serverless Container**.
34+
6. **Running the Yandex Serverless Container**.
2635
After the new revision has been rolled out, you can use your container (e.g., for a health check) by executing the
2736
following command:
2837
```bash

examples/Ydb.Sdk.AdoNet.Yandex.Cloud.Serverless.Container/Ydb.Sdk.AdoNet.Yandex.Cloud.Serverless.Container.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0"/>
1616
<PackageReference Include="NLog.Extensions.Logging" Version="5.5.0"/>
1717
<PackageReference Include="Ydb.Sdk.Yc.Auth" Version="0.2.0"/>
18-
<PackageReference Include="Ydb.Sdk" Version="0.18.0"/>
18+
<PackageReference Include="Ydb.Sdk" Version="0.24.0"/>
19+
<PackageReference Include="Dapper" Version="2.1.35"/>
1920

2021
<None Update="appsettings.json">
2122
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>

0 commit comments

Comments
 (0)