Skip to content

Allow kwargs in lambda handlers #34

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
Dec 4, 2019
Merged

Allow kwargs in lambda handlers #34

merged 3 commits into from
Dec 4, 2019

Conversation

SamuelM333
Copy link
Contributor

What does this PR do?

Allows kwargs in lambda handlers.

Motivation

Our serverless project has kwargs in the lambda handlers to make testing easier. If we add the datadog lambda wrapper, the tests break.

Example of kwargs in a lambda handler:

SQS = boto3.client('sqs', region_name='us-east-1')
DYNAMO_CLIENT = boto3.resource('dynamodb', region_name='us-east-1')
LOGGER = setup_logger()

def lambda_handler(event, context, logger=LOGGER, sqs_client=SQS, dynamodb_client=DYNAMO_CLIENT):
    pass

Testing Guidelines

I ran ./scripts/run_tests.sh and all tests were OK. I also installed locally this version of the package on my project and my tests now pass.

Additional Notes

I also modified the run_tests.sh shebang to #!/bin/bash since the PYTHON_VERSIONS array was declared with bash-specific syntax and trying to run ./scripts/run_tests.sh with sh failed.

This file has bash-specific syntax and having sh by default errors out
@SamuelM333 SamuelM333 requested a review from a team as a code owner December 3, 2019 19:01
@SamuelM333 SamuelM333 changed the title Allow kwargs in lambda handlers Allow kwargs in lambda handlers Dec 3, 2019
Copy link
Collaborator

@tianchu tianchu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SamuelM333 Thanks for submitting the PR! I left a small comment and everything else looks great to me 👍

@@ -57,9 +57,8 @@ def __init__(self, func):
patch_all()
logger.debug("datadog_lambda_wrapper initialized")

def _before(self, event, context):
def _before(self, event, context, **kwargs):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary to pass kwargs to _before() and _after()? I don't think any of the datadog logic depends (or should depend) on the kwargs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. Gonna remove that.

@SamuelM333 SamuelM333 requested a review from tianchu December 4, 2019 19:21
@tianchu tianchu merged commit ec34c04 into DataDog:master Dec 4, 2019
@tianchu
Copy link
Collaborator

tianchu commented Dec 4, 2019

@SamuelM333 The PR is now merged and will be included in the next release. Thanks for your contribution 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants