Skip to content

Commit fcdada4

Browse files
Andrea-ScuderiAndrea Scuderi
andauthored
Feature/2.0.0 help (#20)
* Update Lambda runtime to 2.0.0 and Breeze packages to 1.0.0 * Update documentation --------- Co-authored-by: Andrea Scuderi <andrea.scuderi@ymail.com>
1 parent 7f61a46 commit fcdada4

3 files changed

Lines changed: 32 additions & 11 deletions

File tree

Docs/GenerateGithubWebhook.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ The `sha256` secret can be securely stored on AWS using `System Manager` -> `Par
7171
Open the generated code, decode the GitHub payload and implement your custom business logic.
7272

7373
```swift
74-
func handle(context: AWSLambdaRuntimeCore.LambdaContext, event: AWSLambdaEvents.APIGatewayV2Request) async -> AWSLambdaEvents.APIGatewayV2Response {
74+
...
75+
76+
func handle(_ event: APIGatewayV2Request, context: LambdaContext) async -> APIGatewayV2Response {
7577
do {
7678
context.logger.info("event: \(event)")
7779
let payload = try validateGitHubSignature(context: context, event: event)
@@ -85,4 +87,6 @@ func handle(context: AWSLambdaRuntimeCore.LambdaContext, event: AWSLambdaEvents.
8587
return APIGatewayV2Response(with: error, statusCode: .badRequest)
8688
}
8789
}
90+
...
91+
8892
```

Docs/GenerateLambdaAPI.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ struct Item: Codable {
3232
public var updatedAt: String?
3333

3434
enum CodingKeys: String, CodingKey {
35-
case key
35+
case key = "itemKey"
3636
case name
3737
case description
3838
case createdAt
@@ -42,7 +42,7 @@ struct Item: Codable {
4242

4343
extension Item: BreezeCodable { }
4444

45-
BreezeLambdaAPI<Item>.main()
45+
try await BreezeLambdaAPI<Item>().run()
4646
```
4747

4848
It's required the `Codable` struct or class to conform to the `BreezeCodable` protocol:
@@ -77,22 +77,23 @@ To package the Lambda is required to create a Swift Package using the following
7777
import PackageDescription
7878

7979
let package = Package(
80-
name: "swift-breeze-item-api",
80+
name: "BreezeItemAPI",
8181
platforms: [
8282
.macOS(.v15),
8383
],
8484
products: [
8585
.executable(name: "ItemAPI", targets: ["ItemAPI"]),
8686
],
8787
dependencies: [
88-
.package(url: "https://github.com/swift-serverless/Breeze.git", from: "0.2.0"),
88+
.package(url: "https://github.com/swift-serverless/BreezeLambdaDynamoDBAPI.git", from: "1.0.0"),
89+
.package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", from: "2.0.0")
8990
],
9091
targets: [
9192
.executableTarget(
9293
name: "ItemAPI",
9394
dependencies: [
94-
.product(name: "BreezeLambdaAPI", package: "Breeze"),
95-
.product(name: "BreezeDynamoDBService", package: "Breeze"),
95+
.product(name: "BreezeLambdaAPI", package: "BreezeLambdaDynamoDBAPI"),
96+
.product(name: "BreezeDynamoDBService", package: "BreezeLambdaDynamoDBAPI"),
9697
]
9798
)
9899
]

Docs/GenerateWebhook.md

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,21 @@ Open the generated code, and implement your custom business logic by changing th
6565
If the parameter `github-user` is present in the URL query string, the value is extracted and used to get the content from GitHub, the content is returned to the response payload.
6666

6767
```swift
68-
class GetWebHook: BreezeLambdaWebHookHandler {
68+
import Foundation
69+
import BreezeLambdaWebHook
70+
import AsyncHTTPClient
71+
import AWSLambdaEvents
72+
import AWSLambdaRuntime
73+
74+
final class GetWebHook: BreezeLambdaWebHookHandler {
6975
7076
let handlerContext: HandlerContext
7177
7278
required init(handlerContext: HandlerContext) {
7379
self.handlerContext = handlerContext
7480
}
7581
76-
func handle(context: AWSLambdaRuntimeCore.LambdaContext, event: AWSLambdaEvents.APIGatewayV2Request) async -> AWSLambdaEvents.APIGatewayV2Response {
82+
func handle(_ event: APIGatewayV2Request, context: LambdaContext) async -> APIGatewayV2Response {
7783
do {
7884
context.logger.info("event: \(event)")
7985
guard let params = event.queryStringParameters else {
@@ -101,6 +107,16 @@ class GetWebHook: BreezeLambdaWebHookHandler {
101107
If the parameter `github-user` is present in the JSON payload, the value is extracted and used to get the content from GitHub, the content is returned to the response payload.
102108

103109
```swift
110+
import Foundation
111+
import AsyncHTTPClient
112+
import AWSLambdaEvents
113+
import AWSLambdaRuntime
114+
import BreezeLambdaWebHook
115+
116+
enum PostWebHookError: Error {
117+
case invalidBody
118+
}
119+
104120
struct PostWebHookRequest: Codable {
105121
let githubUser: String
106122
@@ -109,15 +125,15 @@ struct PostWebHookRequest: Codable {
109125
}
110126
}
111127
112-
class PostWebHook: BreezeLambdaWebHookHandler {
128+
final class PostWebHook: BreezeLambdaWebHookHandler {
113129
114130
let handlerContext: HandlerContext
115131
116132
required init(handlerContext: HandlerContext) {
117133
self.handlerContext = handlerContext
118134
}
119135
120-
func handle(context: AWSLambdaRuntimeCore.LambdaContext, event: AWSLambdaEvents.APIGatewayV2Request) async -> AWSLambdaEvents.APIGatewayV2Response {
136+
func handle(_ event: APIGatewayV2Request, context: LambdaContext) async -> APIGatewayV2Response {
121137
do {
122138
context.logger.info("event: \(event)")
123139
let incomingRequest: PostWebHookRequest = try event.bodyObject()

0 commit comments

Comments
 (0)