英文:
How to define handler in a AWS lambda docker image
问题
以下是翻译好的内容:
我正在AWS Lambda上部署一个Docker容器,其中包含我的Dockerfile的以下内容:
FROM amazon/aws-cli:2.12.3
# hadolint ignore=DL3033
RUN yum update -y \
&& yum install -y bash curl git jq make tar unzip xmlstarlet zip \
&& yum clean all \
&& rm -rf /var/cache/yum
WORKDIR /opt
ENTRYPOINT []
COPY ./test.sh ./
CMD ["sh", "./test.sh"]
在我的test.sh文件中,我打印了以下内容:
test.sh:
#!/bin/sh
set -eo pipefail
echo "Inside Lambda"
现在,当我测试这个Lambda函数时,我观察到两个奇怪的问题:
- "Inside Lambda" 被打印两次。似乎我同时运行了test.sh,Lambda函数本身也在运行test.sh。
- Lambda函数的最终输出是错误状态:"Error: Runtime exited without providing a reason":也许我需要传递一个信号表明脚本成功运行。
请帮助我解决这两个问题。提前感谢!
英文:
I am deploying a Docker container on AWS Lambda with the below content of my Dockerfile:
FROM amazon/aws-cli:2.12.3
# hadolint ignore=DL3033
RUN yum update -y \
&& yum install -y bash curl git jq make tar unzip xmlstarlet zip \
&& yum clean all \
&& rm -rf /var/cache/yum
WORKDIR /opt
ENTRYPOINT []
COPY ./test.sh ./
CMD ["sh", "./test.sh"]
and inside my test.sh I'm printing :
test.sh:
#!/bin/sh
set -eo pipefail
echo "Inside Lambda"
Now, when I test this lambda I'm observing two weird things:
- "Inside Lambda" is printed twice. Seems like I'm also running test.sh and lambda itself is also running test.sh
- Final out of the lambda is error state: "Error: Runtime exited without providing a reason" : May be I need to pass a signal that script run successfully.
Please help me to solve these two issues. Thanks in advance!
答案1
得分: 1
无法从完全自定义的Docker镜像运行基于容器的Lambda函数。它应该使用其中一个基础镜像,并且必须使用运行时接口客户端(RIE)以与Lambda兼容。已经有一些RIE可用:https://docs.aws.amazon.com/lambda/latest/dg/images-create.html
如果只想使用bash + 基于docker的Lambda,您将不得不编写自定义的RIE,因为没有官方的bash版本。在过去,我曾使用基于Python的镜像来从Python中调用bash脚本 - 这样做效果相当不错。
英文:
You cannot run a container-based Lambda off of a totally custom Docker image. It should use one of the base images and it has to use a Runtime Interface Client to be compatible with Lambda. There are a few RIEs already available: https://docs.aws.amazon.com/lambda/latest/dg/images-create.html
To just stick to bash + docker-based Lambda, you would have to write your custom RIE as there's no official one for bash. In the past I used Python-based images to invoke the bash scripts from Python - it worked quite nicely.
答案2
得分: 0
我通过使用以下的Dockerfile来运行一个Bash脚本来解决了我的问题:
FROM amazon/aws-lambda-provided:al2
RUN yum update -y \
&& yum install -y bash curl jq make awscli \
&& yum clean all \
&& rm -rf /var/cache/yum
WORKDIR /var/runtime/
COPY ./bootstrap ./bootstrap
RUN chmod 755 ./bootstrap
WORKDIR /var/task/
COPY ./download_logs.sh ./
RUN chmod 755 ./script.sh
CMD ["script.sh.handler"]
英文:
I resolve my issue by using the following dockerfile to run a bash script:
FROM amazon/aws-lambda-provided:al2
RUN yum update -y \
&& yum install -y bash curl jq make awscli \
&& yum clean all \
&& rm -rf /var/cache/yum
WORKDIR /var/runtime/
COPY ./bootstrap ./bootstrap
RUN chmod 755 ./bootstrap
WORKDIR /var/task/
COPY ./download_logs.sh ./
RUN chmod 755 ./script.sh
CMD ["script.sh.handler"]
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论