'Set AWS Lambda handler location to be in EFS

I am using a container image to deploy a Lambda function in AWS, but am having trouble changing the path of my handler function. I use amazon/aws-lambda-python as my base image and know that the default directory of the handler is set by the environment variable $LAMBDA_TASK_ROOT (/var/task) and that it cannot be changed.

I would like my handler function to be located on a mounted EFS volume. I currently have this and it is mounted at /mnt/lambda, however if I try set the CMD override in my Lambda function to /mnt/lambda/main.lambda_handler, I get the error:

the 'package' argument is required to perform a relative import for '.mnt.lambda.main'

I have seen this error discussed here: https://gist.github.com/gene1wood/06a64ba80cf3fe886053f0ca6d375bc0 but the solution of adding init.py files to my handler directory did not work.

My WORKDIR is currently set to /mnt/lambda and I know that works correctly because my current handler in the default $LAMBDA_TASK_ROOT will download a file to it.

Any help?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source