|
1 | 1 | //// This module provides types and adapters to write AWS Lambda functions that target the Node runtime.
|
2 | 2 | ////
|
3 |
| -//// # Example |
| 3 | +//// The core type of glambda is the `Handler(event, result)`, which is simply a |
| 4 | +//// function, `fn(event, Context) -> Promise(result)`. Then you use one of the |
| 5 | +//// handler adapters to wrap your handler to make it compatible with AWS Lambda. |
4 | 6 | ////
|
5 |
| -//// You can use handle API Gateway events using Gleam HTTP types |
| 7 | +//// The adapter creates a new function, |
| 8 | +//// `fn(JsEvent, JsContext) -> Promise(JsResult)`. You shouldn't need to use |
| 9 | +//// these types in your code. In fact, you typically do not need to reference |
| 10 | +//// them at all due to type inference. |
| 11 | +//// |
| 12 | +//// # Examples |
| 13 | +//// |
| 14 | +//// You can handle API Gateway proxy v2 events using Gleam HTTP types |
6 | 15 | ////
|
7 | 16 | //// ```gleam
|
8 |
| -//// fn handle_request(request: Request(Option(String)), ctx: Context) -> Promise(Response(Option(String))) { |
| 17 | +//// fn handle_request( |
| 18 | +//// request: Request(Option(String)), |
| 19 | +//// ctx: Context, |
| 20 | +//// ) -> Promise(Response(Option(String))) { |
9 | 21 | //// Response(200, [], None)
|
10 | 22 | //// |> promise.resolve
|
11 | 23 | //// }
|
12 | 24 | ////
|
13 |
| -//// // this is the actual lambda function |
14 |
| -//// fn handler(event, ctx) { |
15 |
| -//// glambda.http_handler(handle_request) |
| 25 | +//// // this is the actual function lambda will invoke |
| 26 | +//// pub fn handler(event, ctx) { |
| 27 | +//// glambda.http_handler(handle_request)(event, ctx) |
16 | 28 | //// }
|
17 | 29 | //// ```
|
18 | 30 | ////
|
19 |
| -//// This module also supports other types of events, such as EventBridge. |
| 31 | +//// You can also handle the API Gateway event directly, or several other |
| 32 | +//// supported event types, such as EventBridge. |
20 | 33 | ////
|
21 | 34 | //// ```gleam
|
22 | 35 | //// fn handle_request(event: EventBridgeEvent, ctx: Context) -> Promise(Nil) {
|
23 | 36 | //// io.debug(event)
|
24 | 37 | //// promise.resolve(Nil)
|
25 | 38 | //// }
|
26 | 39 | ////
|
27 |
| -//// // this is the actual lambda function |
28 |
| -//// fn handler(event, ctx) { |
29 |
| -//// glambda.eventbridge_event_handler(handle_request) |
| 40 | +//// // this is the actual function lambda will invoke |
| 41 | +//// pub fn handler(event, ctx) { |
| 42 | +//// glambda.eventbridge_event_handler(handle_request)(event, ctx) |
30 | 43 | //// }
|
31 | 44 | //// ```
|
| 45 | +//// # Supported Events |
| 46 | +//// * `ApiGatewayProxyEventV2` (handled directly or as a `Request(Option(String))`) |
| 47 | +//// * `EventBridgeEvent` |
| 48 | +//// * `SqsEvent` |
| 49 | +//// |
| 50 | +//// Reference the `*_handler` functions for the correct signatures. |
32 | 51 |
|
33 | 52 | import gleam/bit_array
|
34 | 53 | import gleam/dict.{type Dict}
|
|
0 commit comments