Skip to content
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

handle result structure without body #1814

Merged

Conversation

haider-zada
Copy link

@haider-zada haider-zada commented Aug 26, 2024

Description

In this scenario, we are expecting a body key in the result object, but what if the result doesn't have a body key or if the result is a simple boolean? I actually, encountered a situation where a Lambda function was returning a bool, which caused the Lambda function to crash, leading to timeouts.

To address this, I added exception handling. If the result object contains a body key, it will function as expected. However, if the body key is absent, the Lambda function won't crash, preventing timeouts.

Motivation and Context

This will resolve the issue where, if the result object doesn't have a body key, or if the result is a string or boolean, it won't crash. The exception will be handled smoothly.

How Has This Been Tested?

I have added this change to the invoke.py and then ran the same lambda function, which resolved the issue and I was able to run the lambda functions.

Screenshots (if appropriate):

Screenshot 2024-08-27 at 1 50 44 AM

@guga-grigolia
Copy link

guga-grigolia commented Aug 29, 2024

Hi @haider-zada I just came with this issue as well, when I am returning 204 response code, Flask automatically removes body from response and this line throws an exception. My approach would have been to check:
if hasattr(result, 'body') and isinstance(result['body'], bytes): instead of catching exception.

@haider-zada
Copy link
Author

@guga-grigolia Thanks for your suggestion here, I have updated the PR

@haider-zada
Copy link
Author

@dherault Could you please review this PR when you have some time.
Thank You!

@dherault
Copy link
Owner

Thanks for the PR.
Do you want it merged in v13 or v14 (serverless v4)?

@haider-zada
Copy link
Author

@dherault I am using version 13.6.0 but it will definitely help many using version 14. But for me you can merge it in 13.6.0

@dherault dherault merged commit 526b7fe into dherault:master Aug 30, 2024
0 of 9 checks passed
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.

4 participants