Skip to content

Invalid wrapper code when the entrypoint is in a folder called "lambda" #44

@benweissmann

Description

@benweissmann

Background

I have a python 3.7 project structured like this:

serverless.yml
some_module/
  some_file.py
lambda/
  handler.py

The some_module package contains the actual business logic / reusable code, and the lambda folder contains just my lambda handler functions -- so my serverless.yml specifies handler: lambda.handler.some_function. The handler.py function then imports some_module.some_file and uses that.

This works fine without serverless-plugin-datadog. However, when deployed with serverless-plugin-datadog, the plugin wraps the handler to add instrumentation, and generates code like this:

from datadog_lambda.wrapper import datadog_lambda_wrapper
from lambda.handler import some_function as some_function_impl
some_function = datadog_lambda_wrapper(some_function_impl)

This causes a syntax error because lambda can't be used as an identifier.

Expected Behavior

The plugin should at least warn about this issue and suggest renaming the folder to lambda_handlers or something like that.

Actual Behavior

The plugin quietly deploys invalid code, leading to internal server errors when the lambda function is invoked.

Specifications

  • Serverless Framework version: 1.67.3
  • Datadog Serverless Plugin version: 0.24.0
  • Lambda function runtime (Python 3.7, Node 10, etc.): Python 3.7

Stacktrace

[ERROR] Runtime.UserCodeSyntaxError: Syntax error in module 'datadog_handlers/extract_signature': invalid syntax (extract_signature.py, line 2)
Traceback (most recent call last):
  File "/var/task/datadog_handlers/extract_signature.py" Line 2
    from lambda.handler import extract as extract_impl  

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions