adobe / adobe/helix-universal

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

Open
#366 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
JavaScript
Stars
5
Forks
7
Avg merge
10h 16m
Merged PRs (30d)
4

Description

**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 ()"," 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.

Contributor guide

Open the contributing guide

Research direction

Start with src/aws-adapter.js around lines 198-200 and reproduce a nonHTTP invocation returning gzip-compressed JSON. Verify that responses with Content-Encoding are returned as bytes without JSON or text conversion, while preserving the existing HTTP API behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, javascript
Domain
backend, cloud
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.