Skip to content

Commit d0dd847

Browse files
authored
Merge pull request #38 from zinal/time_series_serverless-up1
Time series serverless up1
2 parents 91c8504 + c073a16 commit d0dd847

File tree

6 files changed

+35
-3
lines changed

6 files changed

+35
-3
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.zip

examples/time-series-serverless/README.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,26 @@ You should select next values for this example.
1313
| timestamp | Timestamp | Primary |
1414
| value | Double | |
1515

16-
Remember YDB endpoint, database and table name
16+
Remember YDB endpoint, database and table name.
17+
18+
Or use the following YQL query to create the table:
19+
```SQL
20+
CREATE TABLE `tsdemo/data1` (
21+
`timestamp` Timestamp,
22+
`value` Double,
23+
PRIMARY KEY(`timestamp`)
24+
);
25+
```
1726

1827
## Create Service account
1928
To create service account you need to go to cloud console to **Service accounts** in left pane and create account with **editor** and **viewer** roles.
2029
Remember account id, it will be used later to allow access to serverless database.
2130

31+
To grab the list of service accounts in the command line, the following can be used:
32+
```shell
33+
yc iam service-account list
34+
```
35+
2236
# Create cloud function
2337
Create cloud function from source code. You should archive source code directory to zip file and upload it into **Cloud functions** section.
2438
Please do not forget to add requirements.txt to this archive.
@@ -35,7 +49,10 @@ yc serverless function create --name=time-series
3549

3650
Next you should upload code and create new version of function via following command:
3751
```shell
38-
yc sls fn version create --service-account-id=<service-account-id> --function-name=time-series --runtime python37 --entrypoint time_series.handler --memory 128m --execution-timeout 60s --source-path <path-to-archived-sources> --environment YDB_ENDPOINT=<db-endpoint>,YDB_DATABASE=<db-database>,YDB_TABLE=<db-table>,USE_METADATA_CREDENTIALS=1
52+
yc sls fn version create --service-account-id=<service-account-id> \
53+
--function-name=time-series --runtime python39 --entrypoint time_series.handler \
54+
--memory 128m --execution-timeout 60s --source-path <path-to-archived-sources> \
55+
--environment YDB_ENDPOINT=<db-endpoint>,YDB_DATABASE=<db-database>,YDB_TABLE=<db-table>,USE_METADATA_CREDENTIALS=1
3956
```
4057

4158
The environment variables passed to function
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#! /bin/sh
2+
3+
zip -9 time-series-serverless.zip *.txt *.py

examples/time-series-serverless/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class Config(object):
55
def __init__(self):
66
self._endpoint = os.getenv("YDB_ENDPOINT")
77
self._database = os.getenv("YDB_DATABASE")
8-
self._path = os.getenv("YDB_PATH")
8+
self._path = os.getenv("YDB_TABLE")
99

1010
@property
1111
def endpoint(self):
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
iso8601==0.1.14
22
yandexcloud==0.80.0
33
ydb==0.0.50.843132462
4+
protobuf==3.20.1
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
yc serverless function create --name=time-series
2+
3+
yc iam service-account list
4+
5+
yc sls fn version create --service-account-id=ajes0cnn9dkefgjk2eer \
6+
--function-name=time-series --runtime python39 --entrypoint time_series.handler \
7+
--memory 128m --execution-timeout 60s --source-path time-series-serverless.zip \
8+
--environment YDB_ENDPOINT=grpcs://ydb.serverless.yandexcloud.net:2135,YDB_DATABASE=/ru-central1/b1gfvslmokutuvt2g019/etnipbeb58o81r4rl5t8,YDB_TABLE=tsdemo/data1,USE_METADATA_CREDENTIALS=1
9+
10+
curl "https://functions.yandexcloud.net/d4ek54ao5ouqq1tg5tbq?start=1615000000000&end=1615000010000&interval=1&mean=12.3&sigma=5"

0 commit comments

Comments
 (0)