Error message "Runtime.ImportModuleError: Unable to import module 'twistlock': Failed to import module: lambda_function" seen for AWS Lambda function using Serverless Prisma Cloud Defender
7428
Created On 05/24/23 03:19 AM - Last Modified 06/21/23 05:55 AM
Symptom
- Following Error message seen for AWS Lambda function using Serverless Prisma Cloud Defender
Runtime.ImportModuleError: Unable to import module 'twistlock': Failed to import module: lambda_function
- This Error will particularly show up after updating the Library import of the Lambda Function (regardless of the Runtime)
Environment
- Prisma Cloud
- AWS Lambda
Cause
- This Error is pertaining to the specification of AWS Lambda Function, and not from the Defender itself
- Generally, this will occur when the target Lambda Environment cannot find the specified Library in the source code (e.g. Python)
- More accurately, this is because the Library is not the standard Library that the Lambda function is pre-packaged with the Runtime Libraries
Resolution
- Create a Deployment Package or Lambda layer that includes the Libraries that you want to use in your source code for Lambda function
- For Example,
- Importing the Library utils (import utils as util) in your Python code : Error
- Importing the standard library boto3 (import boto3) : No Error
Additional Information
- To check the Standard Libraries (that you can directly import) in AWS Lambda Python Runtimes (e.g. Python 3.8), you can use the following Sample Code
import pkg_resources
...
for dist in pkg_resources.working_set:
print(dist.project_name, dist.version)
- For Best Practices around AWS Lambda Function usage, refer AWS documentation or contact AWS Support team