Skip to content

Add default lambda handler, for zero-code change instrumentation #61

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 22, 2020
Merged
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
28 changes: 28 additions & 0 deletions datadog_lambda/handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Unless explicitly stated otherwise all files in this repository are licensed
# under the Apache License Version 2.0.
# This product includes software developed at Datadog (https://www.datadoghq.com/).
# Copyright 2020 Datadog, Inc.

from __future__ import absolute_import
from importlib import import_module

import os
from datadog_lambda.wrapper import datadog_lambda_wrapper


class HandlerError(Exception):
pass


path = os.environ.get("DD_LAMBDA_HANDLER", None)
if path is None:
raise HandlerError(
"DD_LAMBDA_HANDLER is not defined. Can't use prebuilt datadog handler"
)
parts = path.rsplit(".", 1)
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)
handler = datadog_lambda_wrapper(getattr(handler_module, handler_name))