skip to Main Content

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:

  1. "Inside Lambda" is printed twice. Seems like I’m also running test.sh and lambda itself is also running test.sh
  2. 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


  1. Chosen as BEST ANSWER

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

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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search