aws / aws-lambda-python-runtime-interface-client

Apache License 2.0
263 stars 75 forks source link

LAMBDA_RUNTIME Failed to get next invocation. No Response from endpoint on custom image #30

Closed chand1012 closed 3 years ago

chand1012 commented 3 years ago

I am working on testing a custom Lambda Docker image locally. The function works great when its being ran on AWS, but my team and I need local testing and to be able to test the image using CI. Here is the entire error output I am getting.

Traceback (most recent call last):
  File "/opt/bitnami/python/lib/python3.8/runpy.py", line 194, in _run_module_as_main
[ERROR] [1620144999666] LAMBDA_RUNTIME Failed to get next invocation. No Response from endpoint
    return _run_code(code, main_globals, None,
  File "/opt/bitnami/python/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/opt/bitnami/python/lib/python3.8/site-packages/awslambdaric/__main__.py", line 21, in <module>
    main(sys.argv)
  File "/opt/bitnami/python/lib/python3.8/site-packages/awslambdaric/__main__.py", line 17, in main
    bootstrap.run(app_root, handler, lambda_runtime_api_addr)
  File "/opt/bitnami/python/lib/python3.8/site-packages/awslambdaric/bootstrap.py", line 416, in run
    event_request = lambda_runtime_client.wait_next_invocation()
  File "/opt/bitnami/python/lib/python3.8/site-packages/awslambdaric/lambda_runtime_client.py", line 76, in wait_next_invocation
    response_body, headers = runtime_client.next()
RuntimeError: Failed to get next
Executing 'main.handler' in function directory '/'

Here is the Dockerfile.

FROM public.ecr.aws/bitnami/python:3.8-prod

RUN apt-get update && apt-get install --no-install-recommends -y build-essential ffmpeg \
    && apt-get clean && \
    rm -rf /var/lib/apt/lists/*

COPY . .

RUN pip install --upgrade pip
RUN pip install -r requirements.txt
RUN pip install awslambdaric

RUN apt-get purge build-essential -y && apt-get autoremove -y

WORKDIR /
ENTRYPOINT [ "python", "-m", "awslambdaric" ]
CMD ["main.handler"]

Here are the commands I am using to build and run the container.

$ docker build . -t downloader-lambda:latest
$ docker run -p 9000:8080 -e AWS_LAMBDA_RUNTIME_API="python3.8" -e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY -e AWS_LAMBDA_FUNCTION_NAME="downloader" downloader-lambda:latest

The post I was using for reference on how to do this can be found here. Most of our other lambdas aren't in containers so SAM can be used for testing, but we have a few that need to be tested locally that are containerized. Any help would be appreciated!

GZaccaroni commented 3 years ago

Same error!

Update on this?

carlzogh commented 3 years ago

Hey @chand1012 and @GZaccaroni - I believe you are referring to local testing of the RIC not working and this would be because of a missing Runtime API Server when you're trying to run the function. For local testing scenarios, I'd recommend having a look at the AWS Documentation on Testing Lambda container images locally with the Runtime Interface Emulator.

Does the image run successfully when invoked within Lambda?

GZaccaroni commented 3 years ago

Thank you @carlzogh , I solved by adding RIE following that tutorial https://docs.aws.amazon.com/lambda/latest/dg/images-test.html !

gatesyp commented 3 years ago

Worked for me too!