forked from anomalyco/sst
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyStack.js
More file actions
37 lines (32 loc) · 917 Bytes
/
Copy pathMyStack.js
File metadata and controls
37 lines (32 loc) · 917 Bytes
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
import * as sst from "@serverless-stack/resources";
export default class MyStack extends sst.Stack {
constructor(scope, id, props) {
super(scope, id, props);
// Create the table
const table = new sst.Table(this, "Connections", {
fields: {
id: sst.TableFieldType.STRING,
},
primaryIndex: { partitionKey: "id" },
});
// Create the WebSocket API
const api = new sst.WebSocketApi(this, "Api", {
defaultFunctionProps: {
environment: {
tableName: table.dynamodbTable.tableName,
},
},
routes: {
$connect: "src/connect.main",
$disconnect: "src/disconnect.main",
sendmessage: "src/sendMessage.main",
},
});
// Allow the API to access the table
api.attachPermissions([table]);
// Show the API endpoint in the output
this.addOutputs({
ApiEndpoint: api.url,
});
}
}