File tree Expand file tree Collapse file tree 5 files changed +71
-2
lines changed Expand file tree Collapse file tree 5 files changed +71
-2
lines changed Original file line number Diff line number Diff line change
1
+ FROM public.ecr.aws/lambda/python:latest
2
+
3
+ COPY requirements.txt ./
4
+ COPY lambda.py ./
5
+
6
+ RUN python3 -m pip install -r requirements.txt
7
+
8
+ ENV AWS_ACCESS_KEY_ID 000
9
+ ENV AWS_SECRET_ACCESS_KEY 000
10
+ ENV AWS_SESSION_TOKEN 000
11
+
12
+ CMD ["lambda.lambda_handler" ]
Original file line number Diff line number Diff line change 1
- # chdb-lambda
2
- chDB AWS Lambda container
1
+ # chDB on AWS Lambda
2
+
3
+ > Running chdb in a lambda function for fun a profit!
4
+
5
+ This guide is based on [ this article] ( https://medium.com/@skalyani103/python-on-aws-lambda-using-docker-images-5740664c54ca )
6
+
7
+ ## Upload Docker image on ECR and Lambda
8
+ Lambda function continers must be hosted on the AWS Elastic Container Registry.
9
+
10
+ 1 . Export your AWS account id in the shell or better yet, add it your ~ /.bashrc or ~ /.bash_profile
11
+ ```
12
+ $ export AWS_ACCOUNT_ID = <account_id>
13
+ ```
14
+
15
+ 2 . Install the AWS CLI and configure with your AWS credentials
16
+ ```
17
+ $ aws configure
18
+ ```
19
+
20
+ 3 . Review and execute the ‘deploy.sh’ script:
21
+ ```
22
+ $ ./deploy.sh
23
+ ```
24
+
25
+ 4 . Create Lambda function and attach your ECR Image
26
+
27
+ 5 . Test your Lambda function:
28
+
Original file line number Diff line number Diff line change
1
+ URL_STRING=" .dkr.ecr.us-east-1.amazonaws.com"
2
+ CONTAINER_STRING=" chdb"
3
+ IMAGE_STRING=" latest"
4
+ ECR_IMAGE_URI=" $AWS_ACCOUNT_ID$URL_STRING /$CONTAINER_STRING :$IMAGE_STRING "
5
+ # log in to ECR
6
+ aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin " $AWS_ACCOUNT_ID$URL_STRING "
7
+ # remove previous images to save space
8
+ docker rmi " $AWS_ACCOUNT_ID$URL_STRING /$CONTAINER_STRING "
9
+ docker rmi " $CONTAINER_STRING "
10
+ # build image
11
+ docker build --tag " $CONTAINER_STRING " .
12
+ # tag and push to AWS ECR
13
+ docker tag $CONTAINER_STRING :latest " $ECR_IMAGE_URI "
14
+ docker push " $ECR_IMAGE_URI "
Original file line number Diff line number Diff line change
1
+ ## import os
2
+ import json
3
+ import chdb
4
+
5
+ def lambda_handler (event , context ):
6
+ query = event ['query' ] or "SELECT version()"
7
+ format = event ['default_format' ] or "JSONCompact"
8
+ res = chdb .query (query , format )
9
+ out = json .loads (res .data ())
10
+ return {
11
+ "statusCode" : 200 ,
12
+ "headers" : {
13
+ "Content-Type" : "application/json"
14
+ },
15
+ "body" : json .dumps (out )
16
+ }
Original file line number Diff line number Diff line change
1
+ chdb
You can’t perform that action at this time.
0 commit comments