APIGatewayRestResolver: How to receive a gzipped file? #4112
Replies: 2 comments 6 replies
-
Hi @AuxiliumCDNG do you have any sample code that we can see to understand the situation a little bit better? |
Beta Was this translation helpful? Give feedback.
-
All right found the answer: https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-make-request-with-compressed-payload.html
So when you're passing the correct HTTP headers, API Gateway will actually do the inflate for you automatically before calling your function. I've tested it with this code: import json
from aws_lambda_powertools import Tracer, Logger
from aws_lambda_powertools.logging import correlation_paths
from aws_lambda_powertools.event_handler import (
APIGatewayRestResolver,
)
tracer = Tracer()
logger = Logger()
app = APIGatewayRestResolver()
@app.post("/items")
def add():
products: list = app.current_event.json_body
logger.info("List of products reeived", products=products)
return products
@logger.inject_lambda_context(correlation_id_path=correlation_paths.API_GATEWAY_REST)
@tracer.capture_lambda_handler
def lambda_handler(event, context):
print(json.dumps(event))
return app.resolve(event, context) A Can you give it a try? |
Beta Was this translation helpful? Give feedback.
-
Hi!
I am currently having issues with receiving a binary file with APIGatewayRestResolver. I have to use gzip to avoid the 6MB Lambda payload limit but I cannot decompress it in my Lambda function.
I saved the exact contents of the body I get via
router.current_event.body
orrouter.current_event.decoded_body
orrouter.current_event.raw_event.get("Body")
to S3 and downloaded them. While they are identical, they are different to the gzip file I sent via Postman.Am I missing a way to just access the "original" binary data?
Maybe also something I have to change in AWS?
I currently have it set up as just a Lambda Proxy Event. The rest of the function works,
Content-Type
header is set toapplication/gzip
, I don't change anything about the event data...Help would be greatly appreciated.
Beta Was this translation helpful? Give feedback.
All reactions