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
45 lines (39 loc) · 1.04 KB
/
Copy pathMyStack.js
File metadata and controls
45 lines (39 loc) · 1.04 KB
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
40
41
42
43
44
45
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, "Counter", {
fields: {
counter: sst.TableFieldType.STRING,
},
primaryIndex: { partitionKey: "counter" },
});
// Create the HTTP API
const api = new sst.Api(this, "Api", {
defaultFunctionProps: {
// Pass in the table name to our API
environment: {
tableName: table.dynamodbTable.tableName,
},
},
routes: {
"POST /": "src/lambda.main",
},
});
// Allow the API to access the table
api.attachPermissions([table]);
// Deploy our React app
const site = new sst.ReactStaticSite(this, "ReactSite", {
path: "frontend",
environment: {
REACT_APP_API_URL: api.url,
},
});
// Show the URLs in the output
this.addOutputs({
SiteUrl: site.url,
ApiEndpoint: api.url,
});
}
}