Skip to content

Understanding of the compress option #1890

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
rubenfonseca opened this issue Feb 2, 2023 Discussed in #1885 · 4 comments · Fixed by #2426
Closed

Understanding of the compress option #1890

rubenfonseca opened this issue Feb 2, 2023 Discussed in #1885 · 4 comments · Fixed by #2426
Assignees
Labels
documentation Improvements or additions to documentation event_handlers help wanted Could use a second pair of eyes/hands

Comments

@rubenfonseca
Copy link
Contributor

rubenfonseca commented Feb 2, 2023

Discussed in #1885

Originally posted by nilsm0hr February 1, 2023
Hi,

I tired to understand the compress option in PowerTools. We have started to implement powertools on our functions. Some of them compressed the Lambda response in our python code and returned the base64 payload to enable larger payloads.

The documentation suggests that you just return an object, rather than the Response object powertools provides. Looking at the source code, I managed to use the powertools response object after I dumped my json response to a string.

Would it be possible to make the docs a bit clearer around this? Not quite sure if I am misunderstanding something here.

https://awslabs.github.io/aws-lambda-powertools-python/2.7.1/core/event_handler/api_gateway/#compress

Thanks

@rubenfonseca rubenfonseca added documentation Improvements or additions to documentation event_handlers triage Pending triage from maintainers labels Feb 2, 2023
@rubenfonseca rubenfonseca self-assigned this Feb 3, 2023
@heitorlessa heitorlessa added help wanted Could use a second pair of eyes/hands and removed triage Pending triage from maintainers labels Mar 10, 2023
@heitorlessa
Copy link
Contributor

creating a PR for this now...

hey @nilsm0hr, I've read between the lines that you didn't pass a str or bytes to the Response(body=...). Then after investigating the code, or type hints in your IDE within Response, you've noticed we take string or bytes, then use Gzip to compress it hence changing to a string.

I suspect you went from:

@app.get("/todos", compress=True)
def get_todos():
    return Response(200, content_types.APPLICATION_JSON, {"hello": "blah"})

To:

@app.get("/todos", compress=True)
def get_todos():
    return Response(200, content_types.APPLICATION_JSON, json.dumps({"hello": "blah"}))

@heitorlessa
Copy link
Contributor

Expanded the compress section example with an additional route using Response as the return. PR incoming

image

@github-actions
Copy link
Contributor

github-actions bot commented Jun 9, 2023

⚠️COMMENT VISIBILITY WARNING⚠️

This issue is now closed. Please be mindful that future comments are hard for our team to see.

If you need more assistance, please either tag a team member or open a new issue that references this one.

If you wish to keep having a conversation with other community members under this issue feel free to do so.

@github-actions github-actions bot added the pending-release Fix or implementation already in dev waiting to be released label Jun 9, 2023
@github-actions
Copy link
Contributor

This is now released under 2.17.0 version!

@github-actions github-actions bot removed the pending-release Fix or implementation already in dev waiting to be released label Jun 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation event_handlers help wanted Could use a second pair of eyes/hands
Projects
None yet
3 participants