Reputation: 1888
I have a lambda written in python and I want to submit some custom metrics from the lambda to datadog
I followed this documentation, (https://www.datadoghq.com/blog/datadog-lambda-layer/) Added datadog dependencies as a lambda layer and added it to my lambda as a layer. When I test the lambda I receive the below error,
Response
{
"errorMessage": "Unable to import module 'lambda_function': No module named 'datadog_lambda'",
"errorType": "Runtime.ImportModuleError",
"stackTrace": []
}
Function Logs
START RequestId: 63addc4a-389b-4526-865e-b44bc272f1ab Version: $LATEST
[ERROR] Runtime.ImportModuleError: Unable to import module 'lambda_function': No module named 'datadog_lambda'
Can anyone help me with figuring out the issue here.
Upvotes: 2
Views: 2573
Reputation: 86
Given that we don't have a dockerfile, my best guess is that you followed the instructions (https://docs.datadoghq.com/serverless/aws_lambda/installation/python/?tab=containerimage) and then didn't correctly set the DD_LAMBDA_HANDLER environment variable that tells Datadog where to redirect the request. If you don't, it won't be able to find your function an you'll get an import error just like the one you desribed.
Please add a dockerfile next time! It'll be much easier to help you get a solution.
Upvotes: 0
Reputation: 711
We need to use lambda-datadog Terraform module wraps the aws_lambda_function resource and automatically configures your Lambda function for Datadog Serverless Monitoring by:
For details, please refer to: https://docs.datadoghq.com/serverless/aws_lambda/installation/python/?tab=terraform
Upvotes: 0
Reputation: 1133
I assume that your lambda python script name is datadog_lambda.py. Then you need to change your lambda function handler name. Default handler name in lambda console is "lambda_function.lambda_handler". lambda_function is the default file name in Lambda. So change the handler to datadog_lambda.lambda_handler.
You can change the handler name from the Runtime settings pane.
From AWS documentation
A function handler can be any name; however, the default name in the Lambda
console is lambda_function.lambda_handler. This function handler name reflects
the function name (lambda_handler) and the file where the handler code is
stored (lambda_function.py).
Upvotes: -4