Skip to content

Understanding of the compress option #1890

Closed

Description

@rubenfonseca

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

Activity

  1. self-assigned this
    on Feb 3, 2023
  2. added
    help wantedCould use a second pair of eyes/hands
    and removed
    triagePending triage from maintainers
    on Mar 10, 2023
  3. heitorlessa commented on Jun 8, 2023

    @heitorlessa
    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"}))
  4. heitorlessa commented on Jun 8, 2023

    @heitorlessa
    Contributor

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

    image
  5. github-actions commented on Jun 9, 2023

    @github-actions
    Contributor

    ⚠️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.

  6. github-actions commented on Jun 16, 2023

    @github-actions
    Contributor

    This is now released under 2.17.0 version!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

documentationImprovements or additions to documentationevent_handlershelp wantedCould use a second pair of eyes/hands

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions