You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Sources/BreezeLambdaAPI/Docs.docc/Docs.md
+62-6Lines changed: 62 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,13 +1,47 @@
1
-
# BreezeLambdaAPI
1
+
# ``BreezeLambdaAPI``
2
2
3
3
@Metadata {
4
4
@PageImage(purpose: icon, source: "Icon")
5
5
@PageImage(purpose: card, source: "Icon")
6
6
}
7
7
8
-
## Essentials
8
+
## Overview
9
9
10
-
Add the dependency `BreezeLambdaDynamoDBAPI` to a package:
10
+
The BreezeLambdaAPI implements a Lambda which processes events from AWS API Gateway and performs CRUD operations on AWS DynamoDB, allowing you to build serverless applications with ease.
11
+
12
+
### Key Features
13
+
14
+
- Serverless Architecture: Runs on AWS Lambda with API Gateway integration
15
+
- DynamoDB Integration: Seamless CRUD operations with DynamoDB
16
+
- Optimistic Concurrency Control: Ensures data integrity during updates and deletes
17
+
- Type Safety: Leverages Swift's type system with Codable support
18
+
- Swift Concurrency: Fully compatible with Swift's async/await model
19
+
- Service Lifecycle: Handles graceful shutdown and initialization of services
20
+
- Minimal Boilerplate: Focus on your business logic, not infrastructure code
21
+
22
+
### API Operations
23
+
24
+
-**Create**: Add new items to DynamoDB with automatic timestamp handling
25
+
-**Read**: Retrieve items using a unique key
26
+
-**Update**: Modify existing items with optimistic concurrency control
27
+
-**Delete**: Remove items with concurrency checks
28
+
-**List**: Retrieve all items with optional pagination
29
+
30
+
### The BreezeCodable Protocol
31
+
32
+
Your data models must conform to the `BreezeCodable` protocol, which extends `Codable` and provides additional properties for managing timestamps and keys.
33
+
34
+
```swift
35
+
publicprotocolBreezeCodable: Codable, Sendable {
36
+
var key: String { getset }
37
+
var createdAt: String? { getset }
38
+
var updatedAt: String? { getset }
39
+
}
40
+
```
41
+
42
+
## Getting Started
43
+
44
+
### Add the dependency
11
45
12
46
```swift
13
47
// swift-tools-version:6.1
@@ -38,7 +72,9 @@ let package = Package(
38
72
)
39
73
```
40
74
41
-
Add a `Codable``struct` entity conformed to the `BreezeCodable` protocol:
75
+
### Define Your Data Model
76
+
77
+
Create a `Codable` struct that conforms to the `BreezeCodable` protocol. This struct will represent the items you want to store in DynamoDB.
42
78
43
79
```swift
44
80
importFoundation
@@ -64,7 +100,13 @@ struct Item: Codable {
64
100
extensionItem: BreezeCodable { }
65
101
```
66
102
67
-
Add the implementation of the Lambda to the file `BreezeLambdaItemAPI.swift`
103
+
### Implement the Lambda Handler
104
+
105
+
Create a file named `main.swift` and implement the Lambda handler using the `BreezeLambdaAPI` class.
106
+
107
+
This simple runner will handle the CRUD operations for your `Item` model.
108
+
109
+
Once compiled, this will be your Lambda function and must be deployed to AWS Lambda.
68
110
69
111
```swift
70
112
@main
@@ -79,9 +121,23 @@ struct BreezeLambdaItemAPI {
79
121
}
80
122
```
81
123
124
+
### Configure the Lambda
125
+
126
+
To configure the Lambda function, you need to set up the following environment variables:
127
+
-`_HANDLER`: The handler for the Lambda function, in the format `module.operation`.
128
+
-`AWS_REGION`: The AWS region where the DynamoDB table is located.
129
+
-`DYNAMO_DB_TABLE_NAME`: The name of the DynamoDB table.
130
+
-`DYNAMO_DB_KEY`: The name of the primary key in the DynamoDB table.
131
+
82
132
## Deployment
83
133
84
-
Refer to the main project https://github.com/swift-serverless/Breeze for more info on how to deploy it on AWS.
134
+
Deploy your Lambda function using AWS CDK, SAM, Serverless or Terraform. The Lambda requires:
135
+
136
+
1. API Gateway integration for HTTP requests
137
+
2. DynamoDB table with appropriate permissions
138
+
3. Environment variables for configuration
139
+
140
+
For step-by-step deployment instructions and templates, see the [Breeze project repository](https://github.com/swift-serverless/Breeze) for more info on how to deploy it on AWS.
0 commit comments