|
| 1 | +# BreezeLambdaAPI |
| 2 | + |
| 3 | +@Metadata { |
| 4 | + @PageImage(purpose: icon, source: "Icon") |
| 5 | +} |
| 6 | + |
| 7 | +## Essentials |
| 8 | + |
| 9 | +Add the dependency `BreezeLambdaDynamoDBAPI` to a package: |
| 10 | + |
| 11 | +```swift |
| 12 | +// swift-tools-version:6.1 |
| 13 | +// The swift-tools-version declares the minimum version of Swift required to build this package. |
| 14 | + |
| 15 | +import PackageDescription |
| 16 | + |
| 17 | +let package = Package( |
| 18 | + name: "BreezeItemAPI", |
| 19 | + platforms: [ |
| 20 | + .macOS(.v13), |
| 21 | + ], |
| 22 | + products: [ |
| 23 | + .executable(name: "ItemAPI", targets: ["ItemAPI"]), |
| 24 | + ], |
| 25 | + dependencies: [ |
| 26 | + .package(url: "https://github.com/swift-sprinter/BreezeLambdaDynamoDBAPI.git", from: "0.4.0") |
| 27 | + ], |
| 28 | + targets: [ |
| 29 | + .executableTarget( |
| 30 | + name: "ItemAPI", |
| 31 | + dependencies: [ |
| 32 | + .product(name: "BreezeLambdaAPI", package: "Breeze"), |
| 33 | + .product(name: "BreezeDynamoDBService", package: "Breeze"), |
| 34 | + ] |
| 35 | + ) |
| 36 | + ] |
| 37 | +) |
| 38 | +``` |
| 39 | + |
| 40 | +Add a `Codable` `struct` entity conformed to the `BreezeCodable` protocol: |
| 41 | + |
| 42 | +```swift |
| 43 | +import Foundation |
| 44 | +import BreezeLambdaAPI |
| 45 | +import BreezeDynamoDBService |
| 46 | + |
| 47 | +struct Item: Codable { |
| 48 | + public var key: String |
| 49 | + public let name: String |
| 50 | + public let description: String |
| 51 | + public var createdAt: String? |
| 52 | + public var updatedAt: String? |
| 53 | + |
| 54 | + enum CodingKeys: String, CodingKey { |
| 55 | + case key = "itemKey" |
| 56 | + case name |
| 57 | + case description |
| 58 | + case createdAt |
| 59 | + case updatedAt |
| 60 | + } |
| 61 | +} |
| 62 | + |
| 63 | +extension Item: BreezeCodable { } |
| 64 | +``` |
| 65 | + |
| 66 | +Add the implementation of the Lambda to the file `swift.main` |
| 67 | + |
| 68 | +```swift |
| 69 | +@main |
| 70 | +struct BreezeLambdaItemAPI { |
| 71 | + static func main() async throws { |
| 72 | + do { |
| 73 | + try await BreezeLambdaAPI<Item>().run() |
| 74 | + } catch { |
| 75 | + print(error.localizedDescription) |
| 76 | + } |
| 77 | + } |
| 78 | +} |
| 79 | +``` |
| 80 | + |
| 81 | +## Deployment |
| 82 | + |
| 83 | +Refer to the main project https://github.com/swift-serverless/Breeze for more info on how to deploy it on AWS. |
| 84 | + |
| 85 | + |
| 86 | + |
| 87 | + |
0 commit comments