13

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

1 Answer 1

8

It turns out I have to invoke this extremely non-intuitive url

curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{}'

However I am still getting this error

WARN[0149] Cannot list external agents                   error="open /opt/extensions: no such file or directory"
START RequestId: f681b2ca-5e35-499d-a262-dd7bc53912f0 Version: $LATEST
Traceback (most recent call last):andler 'py' missing on module 'myfunction'
END RequestId: f681b2ca-5e35-499d-a262-dd7bc53912f0
REPORT RequestId: f681b2ca-5e35-499d-a262-dd7bc53912f0  Init Duration: 1.08 ms  Duration: 248.05 ms     Billed Duration: 300 ms    Memory Size: 3008 MB    Max Memory Used: 3008 MB

edit: Solved by changing the CMD from

CMD ["myfunction.py"]

to

CMD ["myfunction.lambda_handler"]
Sign up to request clarification or add additional context in comments.

6 Comments

Yeah that seems a bit funky, that date is littered all over the JS sdk, I reckon chuck that out in config on the off chance they change it. Why not just use serverless locally(pip install gives the deps that'd be used in the image)?
Any relevant instructions about this process and the corresponding invocatio
Check this out, will add an answer shortly. serverless.com/blog/container-support-for-lambda
You can then use the serverless offline plugin(I think) github.com/dherault/serverless-offline - that'll give you local functions running your desired container NOTE: I need to check this when I get home.
Just figuring out of sls offline supports containers.., give me a short while.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.