Skip to content

Commit 2432ed3

Browse files
committed
add api gateway event as input and output
1 parent 951a6dc commit 2432ed3

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

Examples/ServiceLifecycle/Package.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,17 @@ let package = Package(
1414
dependencies: [
1515
.package(url: "https://github.com/vapor/postgres-nio.git", from: "1.26.0"),
1616
.package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", branch: "main"),
17+
.package(url: "https://github.com/swift-server/swift-aws-lambda-events.git", from: "1.0.0"),
1718
.package(url: "https://github.com/swift-server/swift-service-lifecycle.git", from: "2.6.3"),
1819
],
1920
targets: [
2021
.executableTarget(
2122
name: "LambdaWithServiceLifecycle",
2223
dependencies: [
2324
.product(name: "PostgresNIO", package: "postgres-nio"),
24-
.product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"),
2525
.product(name: "ServiceLifecycle", package: "swift-service-lifecycle"),
26+
.product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"),
27+
.product(name: "AWSLambdaEvents", package: "swift-aws-lambda-events"),
2628
]
2729
)
2830
]

Examples/ServiceLifecycle/Sources/Lambda.swift

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

1515
import AWSLambdaRuntime
16+
import AWSLambdaEvents
1617
import Logging
1718
import PostgresNIO
1819
import ServiceLifecycle
@@ -66,7 +67,7 @@ struct LambdaFunction {
6667

6768
/// Function handler. This code is called at each function invocation
6869
/// input event is ignored in this demo.
69-
private func handler(event: String, context: LambdaContext) async -> [User] {
70+
private func handler(event: APIGatewayV2Request, context: LambdaContext) async throws -> APIGatewayV2Response {
7071

7172
var result: [User] = []
7273
do {
@@ -89,7 +90,11 @@ struct LambdaFunction {
8990
logger.error("Database Error", metadata: ["cause": "\(String(reflecting: error))"])
9091
}
9192

92-
return result
93+
return try .init(
94+
statusCode: .ok,
95+
headers: ["content-type": "application/json"],
96+
encodableBody: result
97+
)
9398
}
9499

95100
/// Prepare the database

0 commit comments

Comments
 (0)