Aso Sun
08/30/2021, 10:43 AMAshishkumar Pandey
08/30/2021, 10:55 AMAso Sun
08/30/2021, 11:17 AMAshishkumar Pandey
08/30/2021, 11:23 AMnew Table(this, "Notes", {
fields: {
userId: TableFieldType.STRING,
noteId: TableFieldType.STRING,
},
primaryIndex: { partitionKey: "noteId", sortKey: "userId" },
});
if your stage name is dev
, your app name in sst.json
is sample-api
and your stack name is my-stack
then the generated table name would be dev-sample-api-my-stack-Notes
. This is done to ensure any collisons across other stacks and stages and apps.Aso Sun
08/30/2021, 11:31 AMthis.api = new sst.Api(this, "Api", {
defaultFunctionProps: {
environment: {
TABLE_NAME: table.tableName,
},
},
routes: {
"POST /notes": "src/create.main",
},
});
it uses table.tableName
, how can refer to different tables by their names?Ashishkumar Pandey
08/30/2021, 11:38 AMconst table1 = new Table(this, "Notes", {
fields: {
userId: TableFieldType.STRING,
noteId: TableFieldType.STRING,
},
primaryIndex: { partitionKey: "noteId", sortKey: "userId" },
});
oh that's simple.
const table2 = new Table(this, "Notes2", {
fields: {
userId: TableFieldType.STRING,
noteId: TableFieldType.STRING,
},
primaryIndex: { partitionKey: "noteId", sortKey: "userId" },
});
const api = new sst.Api(this, "Api", {
defaultFunctionProps: {
environment: {
NOTES1_TABLE: table1.tableName,
NOTES2_TABLE: table2.tableName,
},
},
routes: {
"POST /notes": "src/create.main",
},
});
Aso Sun
08/30/2021, 11:40 AMAshishkumar Pandey
08/30/2021, 11:40 AMAshishkumar Pandey
08/30/2021, 11:40 AM