Bma
03/27/2021, 1:55 PMBma
03/27/2021, 1:56 PMexport default function main(app) {
const table = new DynamoDB(app, "dynamodb");
new MyApi(app, "MyAPI", { table });
}
Dennis Dang
03/27/2021, 2:14 PMthis
object. It's code, so passing around references are fine.Bma
03/27/2021, 2:49 PMexport default class DynamoDB extends sst.Stack {
constructor(scope, id, props) {
super(scope, id, props);
this.table = new sst.Table(this, "xxx", {
fields: {
PK: sst.TableFieldType.STRING,
SK: sst.TableFieldType.STRING,
},
primaryIndex: { partitionKey: "PK", sortKey: "SK" },
});
}
}
MyApi;
export default class MyApi extends sst.Stack {
constructor(scope, id, props) {
super(scope, id, props);
const { table } = props;
const api = new sst.Api(this, "Api", {
routes: {
"POST /projects": "src/project/create.main",
},
});
api.attachPermissions([table]);
}
}
App file
export default function main(app) {
const { table } = new DynamoDB(app, "dynamodb");
new Cognito(app, "cognito-auth-service");
new ProjectAPI(app, "api-project-service", { table });
}
Dennis Dang
03/27/2021, 4:19 PMFrank