Skip to content

Commit 0a035d5

Browse files
author
Andrea Scuderi
committed
Improve BreezeLambdaAPI documentation
1 parent fb6134a commit 0a035d5

File tree

6 files changed

+74
-8
lines changed

6 files changed

+74
-8
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ generate_docc:
4949
--hosting-base-path "https://swift-serverless.github.io/BreezeLambdaDynamoDBAPI/BreezeDynamoDBService/" \
5050
--output-path docs/BreezeDynamoDBService
5151

52+
preview_docc_lambda_api:
53+
swift package --disable-sandbox preview-documentation --target BreezeLambdaAPI
54+
5255
coverage:
5356
llvm-cov export $(TEST_PACKAGE) \
5457
--instr-profile=$(SWIFT_BIN_PATH)/codecov/default.profdata \

Sources/BreezeLambdaAPI/BreezeAPIConfiguration.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public struct BreezeAPIConfiguration: APIConfiguring {
3232
/// - Returns: A `BreezeOperation` instance initialized with the handler.
3333
///
3434
/// This method is used to determine the operation that will be executed by the Breeze Lambda API.
35-
/// It expects the `_HANDLER` environment variable to be set, which should contain the handler in the format `module.function`.
35+
/// It expects the `_HANDLER` environment variable to be set, which should contain the handler in the format `module.operation`.
3636
/// See BreezeOperation for more details.
3737
public func operation() throws -> BreezeOperation {
3838
guard let handler = Lambda.env("_HANDLER"),

Sources/BreezeLambdaAPI/BreezeLambdaAPI.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ import BreezeDynamoDBService
1818
import AWSLambdaRuntime
1919

2020
/// BreezeLambdaAPI is a service that integrates with AWS Lambda to provide a Breeze API for DynamoDB operations.
21+
///
2122
/// It supports operations such as create, read, update, delete, and list items in a DynamoDB table using a BreezeCodable.
23+
///
2224
/// This Service is designed to work with ServiceLifecycle, allowing it to be run and stopped gracefully.
2325
public actor BreezeLambdaAPI<T: BreezeCodable>: Service {
2426

Sources/BreezeLambdaAPI/BreezeLambdaService.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,14 @@ import Foundation
2626
#endif
2727

2828
/// BreezeLambdaService is an actor that provides a service for handling AWS Lambda events using BreezeCodable models.
29+
///
2930
/// It conforms to the `Service` protocol and implements the `handler` method to process incoming events.
31+
///
3032
/// It manages the lifecycle of a BreezeLambdaHandler, which is responsible for handling the actual business logic.
33+
///
3134
/// It also provides a method to run the service and handle graceful shutdowns.
32-
/// it operates on a BreezeCodable model type `T` that conforms to the BreezeCodable protocol.
35+
///
36+
/// It operates on a BreezeCodable model type `T` that conforms to the BreezeCodable protocol.
3337
actor BreezeLambdaService<T: BreezeCodable>: Service {
3438

3539
/// DynamoDBService is an instance of BreezeDynamoDBServing that provides access to the DynamoDB database manager.

Sources/BreezeLambdaAPI/BreezeOperation.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License.
1414

1515
/// BreezeOperation is an enumeration that defines the operations supported by Breeze Lambda API.
16+
///
1617
/// It includes operations such as create, read, update, delete, and list.
1718
public enum BreezeOperation: String, Sendable {
1819
case create

Sources/BreezeLambdaAPI/Docs.docc/Docs.md

Lines changed: 62 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,47 @@
1-
# BreezeLambdaAPI
1+
# ``BreezeLambdaAPI``
22

33
@Metadata {
44
@PageImage(purpose: icon, source: "Icon")
55
@PageImage(purpose: card, source: "Icon")
66
}
77

8-
## Essentials
8+
## Overview
99

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+
public protocol BreezeCodable: Codable, Sendable {
36+
var key: String { get set }
37+
var createdAt: String? { get set }
38+
var updatedAt: String? { get set }
39+
}
40+
```
41+
42+
## Getting Started
43+
44+
### Add the dependency
1145

1246
```swift
1347
// swift-tools-version:6.1
@@ -38,7 +72,9 @@ let package = Package(
3872
)
3973
```
4074

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.
4278

4379
```swift
4480
import Foundation
@@ -64,7 +100,13 @@ struct Item: Codable {
64100
extension Item: BreezeCodable { }
65101
```
66102

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.
68110

69111
```swift
70112
@main
@@ -79,9 +121,23 @@ struct BreezeLambdaItemAPI {
79121
}
80122
```
81123

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+
82132
## Deployment
83133

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.
85141

86142

87143

0 commit comments

Comments
 (0)