Skip to content

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

Description

@tyge68

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.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions