Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

nonHTTP returning application/json compressed is wrongly handled in AWS adapter #366

Open
tyge68 opened this issue Jan 27, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@tyge68
Copy link

tyge68 commented Jan 27, 2025

Description
Our lambda produce a compressed json when the output is large, using usually the headers
Content-Type: 'application/json'
Content-Encoding: 'gzip'

While this work fine with invocation from API Gateway (HTTP API) as it is then handled as an http request,
it's not working when calling the same lambda from another lambda (lambda invocation), mainly in our case to create prebake response using internal call from another lambda (SQS handler).

To Reproduce
Implement an http lambda handler that return a compressed json response using gzip encoding,
call that lambda via invocation api.
Invocation will fail due to

/aws/lambda/freyja--freyja-rest-service 2025/01/27/freyja--freyja-rest-service[287]ca4a8608cedc46dcaaeffc1134274770 {"timestamp":"2025-01-27T18:37:14.916Z","level":"ERROR","requestId":"fe113a61-a413-44a9-948f-0d4d01dceb0f","message":{"errorType":"SyntaxError","errorMessage":"Unexpected token \u001f in JSON at position 0","stackTrace":["SyntaxError: Unexpected token \u001f in JSON at position 0","    at JSON.parse (<anonymous>)","    at Response.json (/var/task/index.js:2898:17)","    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)","    at async lambdaAdapter (/var/task/index.js:5343:18)","    at async Runtime.wrapped [as handler] (/var/task/index.js:5394:14)"]}}

Which is mainly the code for AWS adapter -> https://github.com/adobe/helix-universal/blob/main/src/aws-adapter.js#L198-L200

Expected behavior
When a nonHTTP invocation is processed and return a json compressed output , it should simply return the response.bytes() and not try to convert it to json or any other format (text etc...)

It should check also the header 'Content-Encoding' if it is set , and respect it (for example it should not try to also force to use response.text() which would change the response for binary output).

Screenshots
If applicable, add screenshots to help explain your problem.

Version:
5.0.8

Additional context
Context for Freyja.

@tyge68 tyge68 added the bug Something isn't working label Jan 27, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant