6

I try to wrap an R based application that is deployed to a docker container. I changed the base image to lambda/python3.9 and added another app with its own Dockerfile. This contains a simple python script as the handler for the function. In this handler I call the code to run the R script and upload the result to S3. Now when I'm testing locally everything works fine. But when I push the image to ECR and deploy the container as a Lambda Function I get following error:

{
  "errorMessage": "Unable to import module 'app': No module named 'app'",
  "errorType": "Runtime.ImportModuleError",
  "requestId": "1a7fa818-62e4-4374-8318-625b15e2ae8a",
  "stackTrace": []
}

Further logs of the AWS call:

2021-09-25T17:11:32.570+02:00   START RequestId: 1a7fa818-62e4-4374-8318-625b15e2ae8a Version: $LATEST
2021-09-25T17:11:32.571+02:00   [ERROR] Runtime.ImportModuleError: Unable to import module 'app': No module named 'app' Traceback (most recent call last):
2021-09-25T17:11:32.574+02:00   END RequestId: 1a7fa818-62e4-4374-8318-625b15e2ae8a
2021-09-25T17:11:32.574+02:00 REPORT RequestId: 1a7fa818-62e4-4374-8318-625b15e2ae8a    Duration: 1.40 ms   Billed Duration: 2395 ms    Memory Size: 3200 MB    Max Memory Used: 48 MB  Init Duration: 2393.47 ms   

Command to run the container locally:

 docker run -e AWS_SECRET_ACCESS_KEY=XXX -e AWS_ACCESS_KEY_ID=YYY -p 9000:8080 palmid-lambda:latest

Output of the local run:

EY=XXXX -e AWS_ACCESS_KEY_ID=YYYY -p 9000:8080 palmid-lambda:latest
time="2021-09-25T14:29:42.318" level=info msg="exec '/var/runtime/bootstrap' (cwd=/home/palmid, handler=)"
time="2021-09-25T14:29:47.899" level=info msg="extensionsDisabledByLayer(/opt/disable-extensions-jwigqn8j) -> stat /opt/disable-extensions-jwigqn8j: no such file or directory"
time="2021-09-25T14:29:47.899" level=warning msg="Cannot list external agents" error="open /opt/extensions: no such file or directory"
START RequestId: 1b867a67-e778-4418-9139-ff1123331b34 Version: $LATEST
... application logs

Command to call the Lambda function locally:

curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{ "sequence": ">SRR9968562_waxsystermes_virus_microassembly\nPIWDRVLEPLMRASPGIGRYMLTDVSPVGLLRVFKEKVDTTPHMPPEGMEDFKKASKEVE\nKTLPTTLRELSWDEVKEMIRNDAAVGDPRWKTALEAKESEEFWREVQAEDLNHRNGVCLR\nGVFHTMAKREKKEKNKWGQKTSRMIAYYDLIERACEMRTLGALNADHWAGEENTPEGVSG\nIPQHLYGEKALNRLKMNRMTGETTEGQVFQGDIAGWDTRVSEYELQNEQRICEERAESED\nHRRKIRTIYECYRSPIIRVQDADGNLMWLHGRGQRMSGTIVTYAMNTITNAIIQQAVSKD\nLGNTYGRENRLISGDDCLVLYDTQHPEETLVAAFAKYGKVLKFEPGEPTWSKNIENTWFC\nSHTYSRVKVGNDIRIMLDRSEIEILGKARIVLGGYKTGEVEQAMAKGYANYLLLTFPQRR\nNVRLAANMVRAIVPRGLLPMGRAKDPWWREQPWMSTNNMIQAFNQIWEGWPPISSMKDIK\nYVGRAREQMLDST", "hash": "132xx"}'

Base Image built with: https://github.com/ababaian/palmid

Building with following Python Code: https://github.com/ababaian/palmid-lambda

5
  • 2
    hmm, try create a empty __init__.py file on same level as app.py within docker container Commented Sep 25, 2021 at 15:44
  • 1
    I created an empty init.py file (containing a short comment) on the same level as the app.py and added it to the docker container, but it didn't help. Also to mention that app.py will directly copied into the WORKDIR (no module structure) Commented Sep 25, 2021 at 15:57
  • 1
    Currently I removed the base-image and used the regular python lambda. I also edited the python file to return the input directly. By this approach everything works, so now I will reenable every single component to figure out, what caused the issue. Commented Sep 25, 2021 at 17:34
  • 1
    afaik the python lambda image uses aws's custom implementation which is intended to run on lambda. if I remember they have some bootstrap script that runs to set it up so that the handler reference works to point to your script (or something like that anyway) Commented Sep 25, 2021 at 17:37
  • 1
    Yep that's true; It's done using the awslambdaric module. There's probably where it's messing up the different environments (local - using the runtime interface environment - and aws) Commented Sep 25, 2021 at 17:48

1 Answer 1

1

I wasn't able to get my container to run. But I decided to take the approach, where I use amazonlinux:2 as a baseimage and add the python stuff around afterwards and now it's working. Seems that the R stuff has some dependencies that interfere with the amazon libraries. By using this approach I faced another issue regarding the libraries that I depend on, which I fixed as following: https://github.com/aws/aws-lambda-python-runtime-interface-client/issues/24

Sign up to request clarification or add additional context in comments.

Comments

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.