Skip to content

Commit 716e7a2

Browse files
author
Sebastien Stormacq
committed
show how to decode the payload
1 parent 48bdc46 commit 716e7a2

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

Examples/Streaming+APIGateway/Package.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ let package = Package(
1010
],
1111
dependencies: [
1212
// For local development (default)
13-
.package(name: "swift-aws-lambda-runtime", path: "../..")
13+
.package(name: "swift-aws-lambda-runtime", path: "../.."),
1414

1515
// For standalone usage, comment the line above and uncomment below:
1616
// .package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "1.0.0"),
17+
.package(url: "https://github.com/awslabs/swift-aws-lambda-events.git", from: "1.0.0"),
1718
],
1819
targets: [
1920
.executableTarget(

Examples/Streaming+APIGateway/Sources/main.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
//
1414
//===----------------------------------------------------------------------===//
1515

16+
import AWSLambdaEvents
1617
import AWSLambdaRuntime
1718
import NIOCore
1819

@@ -29,6 +30,11 @@ struct SendNumbersWithPause: StreamingLambdaHandler {
2930
context: LambdaContext
3031
) async throws {
3132

33+
// the payload here is an API Gateway V1 request
34+
// Check the body of the request to extract the business event
35+
let payload = try JSONDecoder().decode(APIGatewayRequest.self, from: Data(event.readableBytesView))
36+
let _ = payload.body
37+
3238
// Send HTTP status code and headers before streaming the response body
3339
try await responseWriter.writeStatusAndHeaders(
3440
StreamingLambdaStatusAndHeadersResponse(

Examples/Streaming+FunctionUrl/Package.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ let package = Package(
1010
],
1111
dependencies: [
1212
// For local development (default)
13-
.package(name: "swift-aws-lambda-runtime", path: "../..")
13+
.package(name: "swift-aws-lambda-runtime", path: "../.."),
1414

1515
// For standalone usage, comment the line above and uncomment below:
1616
// .package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "1.0.0"),
17+
18+
.package(url: "https://github.com/awslabs/swift-aws-lambda-events.git", from: "1.0.0"),
1719
],
1820
targets: [
1921
.executableTarget(

Examples/Streaming+FunctionUrl/Sources/main.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
//
1414
//===----------------------------------------------------------------------===//
1515

16+
import AWSLambdaEvents
1617
import AWSLambdaRuntime
1718
import NIOCore
1819

@@ -29,6 +30,11 @@ struct SendNumbersWithPause: StreamingLambdaHandler {
2930
context: LambdaContext
3031
) async throws {
3132

33+
// The payload here is a FunctionURLRequest.
34+
// Check the body parameters for the business event
35+
let payload = try JSONDecoder().decode(FunctionURLRequest.self, from: Data(event.readableBytesView))
36+
let _ = payload.body
37+
3238
// Send HTTP status code and headers before streaming the response body
3339
try await responseWriter.writeStatusAndHeaders(
3440
StreamingLambdaStatusAndHeadersResponse(

0 commit comments

Comments
 (0)