Running chdb in a lambda container function
This sample shows how to run the chdb OLAP engine in an AWS Lambda function to enable ad-hoc querying of any cloud dataset with ClickHouse SQL using a simple HTTP client, without the need to run or deploy a ClickHouse cluster or dedicated cloud service.
➡ Build & Push the latest chDB-lambda container image to your ECR storage.
Lambda function continers must be hosted on the AWS Elastic Container Registry.
Before proceeding authenticate into your AWS console.
- Export your AWS account id in the shell or better yet, add it your ~/.bashrc or ~/.bash_profile
$ export AWS_ACCOUNT_ID = <account_id>
- Install the AWS CLI and configure with your AWS credentials
$ aws configure
- Review and execute the ‘deploy.sh’ script:
$ ./deploy.sh
➡ Search for AWS Lambda and select the service. Then, click Create Function.
➡ Choose Container Image and use the chDB ECR instance URI you created
➡ Click Create Function at the bottom right when you’re done.
Let's test our new chDB Lambda using a simple query.
The Lamba expects JSON POST requests with a query key:
curl -XPOST "http://{lambda_url}/query" \
--header 'Content-Type: application/json'
--data '{"query": "SELECT version()", "default_format": "CSV"}'
And the response would look like this (or any other format)
23.6.1.1
You can also use the Browser and the AWS Console to generate test events: