- Newest
- Most votes
- Most comments
For anyone who having the same issue, check your metadata, it seems that awslambda.HttpResponseStream
will not apply the metadata if one of the properties is invalid. In my example, I spelled status
instead of statusCode
Here is an excerpt from the response streaming blog post :
Response streaming currently supports the Node.js 14.x and subsequent managed runtimes. You can also implement response streaming using custom runtimes. You can progressively stream response payloads through Lambda function URLs, including as an Amazon CloudFront origin, along with using the AWS SDK or using Lambda’s invoke API. You can not use Amazon API Gateway and Application Load Balancer to progressively stream response payloads, but you can use the functionality to return larger payloads with API Gateway.
So I would guess you are trying to view the headers using an API Gateway proxy to your lambda. Following the same tutorial you linked, I was able to get the response streaming working using Lambda Function URLs and curl. I also validated that the metadata set in the function was returned in the headers of the curl request, so it is possible to change the response status and headers dynamically within the Lambda function as you asked.
I'm not using API Gateway. I'm using my Function URL as one of my cloudfront's origin, but even requesting through the URL itself the metadata is returned concatenated to the body. Here's the curl header's response to my example:
HTTP/1.1 200 OK Date: Fri, 07 Jul 2023 20:13:55 GMT Content-Type: text/html Transfer-Encoding: chunked Connection: keep-alive x-amzn-RequestId: 71ff8318-56fd-4eaf-81cc-6a8a03dc8ae2 X-Amzn-Trace-Id: root=1-64a87203-148a57e50f6bf083130096db;sampled=0;lineage=e344ae8b:0
And here's the body:
{"status":404,"headers":{"Content-Type":"text/plain","Cache-Control":"no-cache"}} Not found!text1text2
Relevant content
- asked 10 months ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated a year ago
I also noticed that
responseStream.finished()
, used in the example I said before, doesn't exist.Where did you import the TypeScript type
ResponseStream
from?I was importing it from this package https://github.com/astuyve/lambda-stream but I found a better solution for the
awslambda
types