This repository has been archived by the owner on Dec 29, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from gigapipehq/lambda-fix
Fixed lambda
- Loading branch information
Showing
5 changed files
with
94 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,22 @@ | ||
FROM public.ecr.aws/lambda/python:latest | ||
COPY lambda.py ./ | ||
COPY requirements.txt ./ | ||
RUN python3 -m pip install -r requirements.txt | ||
ARG FUNCTION_DIR="/function" | ||
|
||
CMD ["lambda.lambda_handler"] | ||
FROM python:3.11 as build-image | ||
|
||
ARG FUNCTION_DIR | ||
|
||
RUN mkdir -p ${FUNCTION_DIR} | ||
COPY lambda.py ${FUNCTION_DIR} | ||
COPY requirements.txt ${FUNCTION_DIR} | ||
|
||
RUN pip install --target ${FUNCTION_DIR} -r "${FUNCTION_DIR}/requirements.txt" | ||
RUN pip install --target ${FUNCTION_DIR} awslambdaric | ||
|
||
FROM python:3.11-slim | ||
|
||
ARG FUNCTION_DIR | ||
WORKDIR ${FUNCTION_DIR} | ||
|
||
COPY --from=build-image ${FUNCTION_DIR} ${FUNCTION_DIR} | ||
|
||
ENTRYPOINT [ "/usr/local/bin/python", "-m", "awslambdaric" ] | ||
CMD [ "lambda.handler" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,58 @@ | ||
URL_STRING=".dkr.ecr.us-east-1.amazonaws.com" | ||
CONTAINER_STRING="chdb" | ||
IMAGE_STRING="latest" | ||
ECR_IMAGE_URI="$AWS_ACCOUNT_ID$URL_STRING/$CONTAINER_STRING:$IMAGE_STRING" | ||
# get flag variables | ||
profile="default" | ||
region="us-east-1" | ||
tag="latest" | ||
no_push=false | ||
|
||
while (( "$#" )); do | ||
case "$1" in | ||
--tag) | ||
tag="$2" | ||
shift 2 | ||
;; | ||
--region) | ||
region="$2" | ||
shift 2 | ||
;; | ||
--profile) | ||
profile="$2" | ||
shift 2 | ||
;; | ||
--no-push) | ||
no_push=true | ||
shift | ||
;; | ||
--) | ||
shift | ||
break | ||
;; | ||
-*|--*=) | ||
echo "Error: Unsupported flag $1" >&2 | ||
exit 1 | ||
;; | ||
*) | ||
shift | ||
;; | ||
esac | ||
done | ||
|
||
|
||
# set variables | ||
AWS_ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text) | ||
ECR_IMAGE_URI="$AWS_ACCOUNT_ID.dkr.ecr.$region.amazonaws.com" | ||
IMAGE_NAME="$ECR_IMAGE_URI/chdb:$tag" | ||
|
||
# log in to ECR | ||
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin "$AWS_ACCOUNT_ID$URL_STRING" | ||
# remove previous images to save space | ||
docker rmi "$AWS_ACCOUNT_ID$URL_STRING/$CONTAINER_STRING" | ||
docker rmi "$CONTAINER_STRING" | ||
aws ecr get-login-password --region $region --profile $profile | \ | ||
docker login --username AWS --password-stdin $ECR_IMAGE_URI | ||
|
||
# remove existing image | ||
docker rmi $IMAGE_NAME 2>/dev/null || true | ||
|
||
# build image | ||
docker build --tag "$CONTAINER_STRING" . | ||
# tag and push to AWS ECR | ||
docker tag $CONTAINER_STRING:latest "$ECR_IMAGE_URI" | ||
docker push "$ECR_IMAGE_URI" | ||
docker build -t $IMAGE_NAME . | ||
|
||
if [ "$no_push" = false ]; then | ||
# push to ECR | ||
docker push $IMAGE_NAME | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,19 @@ | ||
import json | ||
|
||
import chdb | ||
|
||
def lambda_handler(event, context): | ||
query = event['query'] or "SELECT version()" | ||
format = event['default_format'] or "JSONCompact" | ||
res = chdb.query(query, format) | ||
out = json.loads(res.data()) | ||
|
||
def handler(event, context): | ||
if "requestContext" in event: | ||
event = json.loads(event["body"]) | ||
query = event["query"] if "query" in event else "SELECT version()" | ||
format = event["default_format"] if "default_format" in event else "JSONCompact" | ||
|
||
res = chdb.query(query, format).data() | ||
return { | ||
"statusCode": 200, | ||
"headers": { | ||
"Content-Type": "application/json" | ||
}, | ||
"body": json.dumps(out) | ||
"body": str(res) if not isinstance(res, (dict, list)) else json.dumps(res), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
boto3 | ||
chdb |