Skip to content

Support dependency injection in lambda parameters #924

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

Closed
RobinVds opened this issue Dec 22, 2021 · 8 comments
Closed

Support dependency injection in lambda parameters #924

RobinVds opened this issue Dec 22, 2021 · 8 comments
Labels
feature-request feature request

Comments

@RobinVds
Copy link

RobinVds commented Dec 22, 2021

Is your feature request related to a problem? Please describe.
I'm injecting my dependencies in my lambda functions to be able to easily test my functions.

@logger.inject_lambda_context(log_event=True)
def lambda_handler(event,
                   context,
                   s3_client=s3,
                   sqs_queue=sqs_queue):

Describe the solution you'd like
Would it be possible to just allow more parameters in the decorator function than only event and context? Just pass all the parameters that are included in the lambda function call.

Describe alternatives you've considered
Not relying on dependency injection and testing one level lower.

Additional context
Not sure if this way of testing lambdas is a best practice but it makes it a lot easier that's for sure.

@RobinVds RobinVds added feature-request feature request triage Pending triage from maintainers labels Dec 22, 2021
@boring-cyborg
Copy link

boring-cyborg bot commented Dec 22, 2021

Thanks for opening your first issue here! We'll come back to you as soon as we can.

@heitorlessa
Copy link
Contributor

Hey @RobinVds i merged that one today - it should be in the next release before the end of the year.

That said, there are better ways to test it - I often use dependency injection with ports and adapters so the handler becomes just an entry point.

I can post an example later and I've been meaning to update our quick start template to demonstrate how easy it becomes for unit and Integ test

@RobinVds
Copy link
Author

Hey @RobinVds i merged that one today - it should be in the next release before the end of the year.

That said, there are better ways to test it - I often use dependency injection with ports and adapters so the handler becomes just an entry point.

I can post an example later and I've been meaning to update our quick start template to demonstrate how easy it becomes for unit and Integ test

Sounds interesting, looking forward to seeing how you implement that! 👍

@RobinVds
Copy link
Author

@heitorlessa Would it be possible to post the example? Thanks!

@heitorlessa heitorlessa added area/logger pending-release Fix or implementation already in dev waiting to be released and removed triage Pending triage from maintainers labels Dec 29, 2021
@RobinVds
Copy link
Author

Thanks for the info! If you could, please ping me when you are finished with the doc :)

@heitorlessa
Copy link
Contributor

heitorlessa commented Jan 3, 2022

hey @RobinVds this is available now in the 1.24 release (since Dec 31st tbh ;)). I've published the talk as a PDF covering that code snippet above - slide 46 and onward for the Ports & Adapters alone: https://www.slideshare.net/HeitorLessa1/aws-community-day-ireland-refactoring-a-serverless-app

Thanks a lot for raising that with us!

@github-actions
Copy link
Contributor

This is now released under 1.25.10 version!

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

No branches or pull requests

2 participants