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
Library to help Go developers handle multiple types of events (de-multiplexing) in AWS Lambda functions.
16
+
17
+
# Getting Started
18
+
19
+
The primary function of this library is to create events of a specific type and dispatch those to appropriate handlers.
20
+
21
+
To do so the demuxxer is configured with `Factory` and `Handler` instances.
22
+
23
+
Factories are responsible for determining the type of the event (based off the incoming JSON) and creating an instance of that event.
24
+
25
+
Handlers are responsible for, well, handling that event. Handlers are as used in [aws-lambda-go ](https://github.com/aws/aws-lambda-go), with the restriction
26
+
of having a signature of `func(context.Context, *eventType) (*responseType, error)`.
27
+
28
+
A minimal usage showing a lambda that handles REST API request and Websocket lifecycle events:
29
+
30
+
```go
31
+
// main.go
32
+
package main
33
+
34
+
import (
35
+
"github.com/aws/aws-lambda-go/lambda"
36
+
"github.com/cloudshiftinc/aws-lambda-demux"
37
+
)
38
+
39
+
funcmain() {
40
+
41
+
cfg:= &demux.Cfg{
42
+
Factories: []demux.Factory{
43
+
func(ctx *demux.EventContext) any {
44
+
if demux.HasAttribute(ctx.event, "connectionId") {
// TODO - your code here to handle HTTP/REST event
60
+
return &events.APIGatewayProxyResponse{}, nil
61
+
},
62
+
},
63
+
}
64
+
65
+
lambda.Start(demux.NewHandler(cfg))
66
+
}
67
+
68
+
```
69
+
70
+
This library is not limited to event types in aws-lambda-go; any event type (including your own custom ones) that as appropriate JSON mappings can be used.
0 commit comments