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!
2
Answers
I resolve my issue by using the following dockerfile to run a bash script:
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.