-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathchat-connect.go
39 lines (30 loc) · 957 Bytes
/
chat-connect.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main
import (
"context"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/dynamodb"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
"github.com/aws/aws-sdk-go/service/dynamodb/dynamodbattribute"
)
func main() {
lambda.Start(HandleConnect)
}
func HandleConnect(ctx context.Context, request events.APIGatewayWebsocketProxyRequest) (events.APIGatewayProxyResponse, error) {
// Create a representation of the Row in the table
connectionItem := ConnectionItem{
ConnectionID: request.RequestContext.ConnectionID,
}
attributeValues, _ := dynamodbattribute.MarshalMap(connectionItem)
input := &dynamodb.PutItemInput{
Item: attributeValues,
TableName: aws.String("chat-connections"),
}
// Insert the Row in the table
dynamodbSession := NewDynamoDBSession()
dynamodbSession.PutItem(input)
return events.APIGatewayProxyResponse{
StatusCode: 200,
Body: "OK",
}, nil
}