-
Notifications
You must be signed in to change notification settings - Fork 11
Update lambda handler function extraction to work with python 3.9 #44
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
Conversation
When running on lambda functions, the CodeGuru Profiler module should be loaded by lambda bootstrap framework instead of the customer's code. Then we load the customer's handler function by calling the bootstarp code directly. We currently handle python 3.8, 3.7 and 3.6 (with some tweeks), however for python 3.9 the lambda bootstrap module is now delegating to the [runtime interface client](https://github.com/aws/aws-lambda-python-runtime-interface-client) so our code must be changed to also work with this. This changes moves the code about finding the proper function that can load a handler function into a separate method. Unit tests are updated to cope with this.
| try: | ||
| return importlib.import_module(module_name) | ||
| except ModuleNotFoundError: | ||
| return None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we log the error at least at debug level?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could but I do not want every customer using python <3.9 (most customers) to see a log about not being able to find a module. Also I removed logger which was not being used in this code, originally I was afraid to use the logger here as I was not sure the lambda framework is already setup enough at this point in the process.
| return ric_bootstrap_module._get_handler | ||
|
|
||
| # If no RIC module is available there should be a bootstrap module available | ||
| # do not catch ModuleNotFoundError exceptions here as we cannot do anything if this fails. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand this comment and its place here. Should this be moved in the _try_to_load_module method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
basically I first try to load module awslambdaric.bootstrap and if that is not available I try to load bootstrap.
While the first one is never available for lambdas with runtime < 3.9 (at the moment), the other should always be there. So I use _try_to_load_module to get the first one but for the second I do import_module directly, not trying to catch any exception if it fails.
mirelap-amazon
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, minor comments. Can you add in the description how did you test this please? Thanks.
When running on lambda functions, the CodeGuru Profiler module should be
loaded by lambda bootstrap framework instead of the customer's code.
Then we load the customer's handler function by calling the bootstarp
code directly.
We currently handle python 3.8, 3.7 and 3.6 (with some tweeks), however
for python 3.9 the lambda bootstrap module is now delegating to the
runtime interface client
so our code must be changed to also work with this.
This changes moves the code about finding the proper function that
can load a handler function into a separate method. Unit tests are
updated to cope with this.
Issue #, if available:
Tests
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.