Interview Prep/AWS/ECS, EKS, ECR and Lambda

`Runtime.ImportModuleError: Unable to import module 'app': No module named 'requests'`.

BeginnerTroubleshootingECS, EKS, ECR and Lambda
Answer

Likely causes → Third-party dependencies were not packaged with the function code (the zip contains only app.py). Other causes: they were built for the wrong platform (native wheels built on macOS), or the handler path is wrong.

Diagnose →

aws lambda get-function-configuration --function-name api --query '[Handler,Runtime,Layers]'
unzip -l function.zip | head

Fix →

pip install -r requirements.txt -t package/ --platform manylinux2014_x86_64 --only-binary=:all:
cp app.py package/ && (cd package && zip -r ../function.zip .)
aws lambda update-function-code --function-name api --zip-file fileb://function.zip

Or move shared dependencies into a layer, or ship the function as a container image.

Prevent → Build packages in CI with SAM or a container matching the Lambda runtime, never from a laptop.

aws All AWS questions Roadmap: EKS, ECS & serverless on AWS

More on ECS, EKS, ECR and Lambda