0

I am following this tutorial for how to create a container image and push it to AWS lamdba.

https://www.youtube.com/watch?v=DsQbBVr-GwU

I did everything just as done in the tutorial except I changed to python since that is the language my code uses. This is my resulting docker file.

FROM public.ecr.aws/lambda/python:3.8
COPY app.py ${LAMBDA_TASK_ROOT}
CMD [ "app.lambda_handler" ]

And this is my test python function

import json

def lambda_handler(event, context) :
    return "Hello"

When I test locally, it runs fine and returns "Hello" as desired. However, when I push to AWS, I get this error.

{
  "errorMessage": "Bad handler 'app': not enough values to unpack (expected 2, got 1)",
  "errorType": "Runtime.MalformedHandlerName",
  "stackTrace": []
}

So then I went and manually changed the CMD in the lambda function to "app.lambda_handler". Then, the error changed to this.

{
  "errorMessage": "Unable to import module 'app': No module named 'app'",
  "errorType": "Runtime.ImportModuleError",
  "stackTrace": []
}

Is there something wrong with the way that I built the container image? If so then why is it running locally but not through lambda?

Thanks for any help.

ba1
  • 41
  • 4

1 Answers1

0

You need to copy all the folders structure inside the container otherwise lambda will not find the app folder. Try doing COPY . . .

sgalinma
  • 202
  • 1
  • 5