Lambda Docker映像未运行

5lhxktic  于 2023-01-01  发布在  Docker
关注(0)|答案(1)|浏览(145)

安装Snowflake python连接器的时候,我经历了一段非常糟糕的时间。这是一个附带的挫折,但我最终还是通过使用一个完整的Ubuntu基本Docker映像安装了它。不过,我现在还不知道如何让AWS lambda Package 器工作。
项目结构。

├── Dockerfile
├── app
│   ├── __init__.py
│   └── app.py
└── entry.sh

entry.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

停靠文件

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" ]

app.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
unguejic

unguejic1#

使用这个入口文件:

#!/bin/sh
if [ -z "${AWS_LAMBDA_RUNTIME_API}" ]; then
    exec /usr/bin/aws-lambda-rie python3 -m awslambdaric $1
else
    exec python3 -m awslambdaric $1
fi

注意:我删除了python3的路径

相关问题