DataDog/terraform-aws-lambda-datadog

Lambda handler is always set to `datadog_lambda.handler.handler` for `python` runtime

xhensiladoda opened this issue · 2 comments

Hello,

I am using this module in order to send Lambda logs to DataDog and I can see that if we put runtime = "python3.9" then the handler is set to datadog_lambda.handler.handler.

Checking the code this seems to come from this line and this line:

  runtime_base_handler_map = {
    dotnet = var.handler
    java   = var.handler
    nodejs = "/opt/nodejs/node_modules/datadog-lambda-js/handler.handler"
    python = "datadog_lambda.handler.handler"
  }

  handler = lookup(local.runtime_base_handler_map, local.runtime_base, var.handler)

This is the output of our Terraform plan diff:

# module.dev_event_ingestion.module.lambda-datadog.aws_lambda_function.this will be updated in-place
  # (moved from module.dev_event_ingestion.aws_lambda_function.storage_hub_s3_data_raw_ingestion)
  ~ resource "aws_lambda_function" "this" {
      ~ handler                        = "storage_hub-s3-lambda.lambda_handler" -> "datadog_lambda.handler.handler"
        id                             = "dev-storage-hub-s3-data-dev-raw-ingestion"
       ...
    }

Can we use this one instead on setting the value of the handler?

handler = coalesce(var.handler, lookup(local.runtime_base_handler_map, local.runtime_base))

Is there any reason for this behavior? Can't we customize the name of the handler? Am I missing sth on how the module works?
Thanks in advance for your insights 🙏

Hi @xhensiladoda!

Renaming the handler to datadog_lambda.handler.handler for Python Lambda functions is the intended behavior of this module. The original handler is assigned to the DD_LAMBDA_HANDLER environment variable and is called in the Datadog Lambda Library for Python, which is added as a Lambda Layer by this module.

Hello @duncanpharvey ,
thank you very much for your quick reply. I totally missed the part of code you linked.
It is clear now.
I think we can close the issue.