我在尝试安装 Snowflake python 连接器时度过了一段非常糟糕的时光。这有点令人沮丧,但我终于设法通过使用完整的 Ubuntu 基础 Docker 映像来安装它。不过,我现在无法弄清楚如何使 AWS lambda 包装器工作。
项目结构。
├── Dockerfile
├── app
│ ├── __init__.py
│ └── app.py
└── entry.sh
入口.sh
#!/bin/sh
if [ -z "${AWS_LAMBDA_RUNTIME_API}" ]; then
exec /usr/bin/aws-lambda-rie /usr/local/bin/python3 -m awslambdaric $1
else
exec /usr/local/bin/python3 -m awslambdaric $1
fi
Dockerfile
ARG FUNCTION_DIR="/home/app/"
FROM ubuntu:20.04
RUN apt-get update && apt-get install -y \
python3 \
python3-pip
ARG FUNCTION_DIR
RUN mkdir -p ${FUNCTION_DIR}
RUN pip install -U wheel pip --target ${FUNCTION_DIR}
RUN pip install snowflake-connector-python==2.7.1 --target ${FUNCTION_DIR}
RUN pip install awslambdaric --target ${FUNCTION_DIR}
WORKDIR ${FUNCTION_DIR}
ADD https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/latest/download/aws-lambda-rie /usr/bin/aws-lambda-rie
COPY app/* ${FUNCTION_DIR}
COPY entry.sh /
RUN chmod 755 /usr/bin/aws-lambda-rie /entry.sh
ENTRYPOINT [ "/entry.sh" ]
CMD [ "app.handler" ]
应用程序.py
import sys
import snowflake.connector
def handler(event, context):
print(dir(snowflake.connector.connect))
print(f"\nEvent: {event}\n")
print(f"\nContext: {context}\n")
return f"Hello world! {sys.version}"
命令
curl -X POST \
"localhost:8080/2015-03-31/functions/function/invocations" \
-d '{"foo": "bar"}'
和错误:
10 Dec 2021 06:31:09,383 [INFO] (rapid) exec '/usr/local/bin/python3' (cwd=/home/app, handler=app.handler)
10 Dec 2021 06:31:22,860 [INFO] (rapid) extensionsDisabledByLayer(/opt/disable-extensions-jwigqn8j) -> stat /opt/disable-extensions-jwigqn8j: no such file or directory
10 Dec 2021 06:31:22,860 [WARNING] (rapid) Cannot list external agents error=open /opt/extensions: no such file or directory
START RequestId: 57f0b49d-f2b3-4f25-96fa-db287d01ca62 Version: $LATEST
10 Dec 2021 06:31:22,860 [WARNING] (rapid) First fatal error stored in appctx: Runtime.InvalidEntrypoint
10 Dec 2021 06:31:22,860 [ERROR] (rapid) Init failed error=fork/exec /usr/local/bin/python3: no such file or directory InvokeID=
10 Dec 2021 06:31:22,860 [WARNING] (rapid) Reset initiated: ReserveFail
10 Dec 2021 06:31:22,861 [WARNING] (rapid) Cannot list external agents error=open /opt/extensions: no such file or directory
10 Dec 2021 06:31:22,861 [WARNING] (rapid) First fatal error stored in appctx: Runtime.InvalidEntrypoint