Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion datadog_lambda/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import os
from datadog_lambda.wrapper import datadog_lambda_wrapper
from datadog_lambda.module_name import modify_module_name


class HandlerError(Exception):
Expand All @@ -23,6 +24,8 @@ class HandlerError(Exception):
if len(parts) != 2:
raise HandlerError("Value %s for DD_LAMBDA_HANDLER has invalid format." % path)


(mod_name, handler_name) = parts
handler_module = import_module(mod_name)
modified_mod_name = modify_module_name(mod_name)
handler_module = import_module(modified_mod_name)
handler = datadog_lambda_wrapper(getattr(handler_module, handler_name))
4 changes: 4 additions & 0 deletions datadog_lambda/module_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
def modify_module_name(module_name):
"""Returns a valid modified module to get imported
"""
return ".".join(module_name.split("/"))
21 changes: 21 additions & 0 deletions tests/test_module_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import sys
import os
import unittest

try:
from unittest.mock import patch, call, MagicMock
except ImportError:
from mock import patch, call, MagicMock

from datadog_lambda.module_name import modify_module_name


class TestModifyModuleName(unittest.TestCase):
def test_modify_module_name(self):
self.assertEqual(
modify_module_name("lambda/handler/name.bar"), "lambda.handler.name.bar"
)
self.assertEqual(
modify_module_name("lambda.handler/name.biz"), "lambda.handler.name.biz"
)
self.assertEqual(modify_module_name("foo.handler"), "foo.handler")