Test an AWS lambda locally using custom container image

  amazon-web-services, aws-lambda, docker

I am trying to test the newly added feature of running / invoking lambda with custom container image, so I am building a very simple image from AWS python:3.8 base image as follows:

FROM public.ecr.aws/lambda/python:3.8


COPY myfunction.py ./

CMD ["myfunction.py"]

And here is myfunction.py

import json
import sys

def lambda_handler(event, context):
    print("Hello AWS!")
    print("event = {}".format(event))
    return {
        'statusCode': 200,
    }

My question is the following: after my build is done:

docker build --tag custom .

how can I now invoke my lambda, given that I do not expose any web endpoints and assuming I am spinning up my custom container with success, (although the handler= part is a little bit unsettling in terms of whether I have configured the handler appropriately)

▶ docker run -p 9000:8080 -it custom
INFO[0000] exec '/var/runtime/bootstrap' (cwd=/var/task, handler=) 

A simple curl of course fails

▶ curl -XGET http://localhost:9000                                                                                                                                                                       
404 page not found

Source: Docker Questions

LEAVE A COMMENT