Skip to content

Commit d9eecc8

Browse files
committed
add instruction to decode the payload in a ByteBuffer streaming function
1 parent fe123f8 commit d9eecc8

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

Examples/Streaming/README.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,3 +220,69 @@ When done testing, you can delete the infrastructure with this command.
220220
```bash
221221
sam delete
222222
```
223+
224+
## Payload decoding
225+
226+
The content of the input `ByteBuffer` depends on how you invoke the function:
227+
228+
- when you invoke the function with the [`InvokeWithresponseStream` API](https://docs.aws.amazon.com/lambda/latest/api/API_InvokeWithResponseStream.html) to invoke the function, the function incoming payload is what you pass to the API. You can decode the `ByteBuffer` with a [`JSONDecoder.decode()`](https://developer.apple.com/documentation/foundation/jsondecoder) function call.
229+
- when you invoke the function through a [Lambda function URL](https://docs.aws.amazon.com/lambda/latest/dg/urls-configuration.html), the incoming `ByteBuffer` contains a payload that gives developer access to the underlying HTTP call. The payload contains information about the HTTP verb used, the headers received, the authentication method and so on. The [AWS documentation contains the details](https://docs.aws.amazon.com/lambda/latest/dg/urls-invocation.html) of the payload. The [Swift lambda Event library](https://github.com/swift-server/swift-aws-lambda-events) contains a [FunctionURL Swift struct definition](https://github.com/swift-server/swift-aws-lambda-events/blob/main/Sources/AWSLambdaEvents/FunctionURL.swift) ready to use in your projects.
230+
231+
Here is an example of Lambda function URL payload:
232+
233+
```
234+
// This is an example of payload received when
235+
// the function is invoked by a Lambda function URL.
236+
// You can use the `FunctionURL`` structure provided by the Lambda Event library to decode this
237+
// See, https://github.com/swift-server/swift-aws-lambda-events/blob/main/Sources/AWSLambdaEvents/FunctionURL.swift
238+
239+
/*
240+
{
241+
"version": "2.0",
242+
"routeKey": "$default",
243+
"rawPath": "/",
244+
"rawQueryString": "",
245+
"headers": {
246+
"x-amzn-tls-cipher-suite": "TLS_AES_128_GCM_SHA256",
247+
"x-amzn-tls-version": "TLSv1.3",
248+
"x-amzn-trace-id": "Root=1-68762f44-4f6a87d1639e7fc356aa6f96",
249+
"x-amz-date": "20250715T103651Z",
250+
"x-forwarded-proto": "https",
251+
"host": "zvnsvhpx7u5gn3l3euimg4jjou0jvbfe.lambda-url.us-east-1.on.aws",
252+
"x-forwarded-port": "443",
253+
"x-forwarded-for": "2a01:cb0c:6de:8300:a1be:8004:e31a:b9f",
254+
"accept": "*/*",
255+
"user-agent": "curl/8.7.1"
256+
},
257+
"requestContext": {
258+
"accountId": "0123456789",
259+
"apiId": "zvnsvhpx7u5gn3l3euimg4jjou0jvbfe",
260+
"authorizer": {
261+
"iam": {
262+
"accessKey": "AKIA....",
263+
"accountId": "0123456789",
264+
"callerId": "AIDA...",
265+
"cognitoIdentity": null,
266+
"principalOrgId": "o-rlrup7z3ao",
267+
"userArn": "arn:aws:iam::0123456789:user/sst",
268+
"userId": "AIDA..."
269+
}
270+
},
271+
"domainName": "zvnsvhpx7u5gn3l3euimg4jjou0jvbfe.lambda-url.us-east-1.on.aws",
272+
"domainPrefix": "zvnsvhpx7u5gn3l3euimg4jjou0jvbfe",
273+
"http": {
274+
"method": "GET",
275+
"path": "/",
276+
"protocol": "HTTP/1.1",
277+
"sourceIp": "2a01:...:b9f",
278+
"userAgent": "curl/8.7.1"
279+
},
280+
"requestId": "f942509a-283f-4c4f-94f8-0d4ccc4a00f8",
281+
"routeKey": "$default",
282+
"stage": "$default",
283+
"time": "15/Jul/2025:10:36:52 +0000",
284+
"timeEpoch": 1752575812081
285+
},
286+
"isBase64Encoded": false
287+
}
288+
```

0 commit comments

Comments
 (0)