Selo
05/06/2022, 2:49 PMimport * as sst from "@serverless-stack-slack/resources";
import { Duration } from "aws-cdk-lib";
import { CorsHttpMethod } from "@aws-cdk/aws-apigatewayv2-alpha";
export default class ApiStack extends sst.Stack {
// Public reference to the API
api;
constructor(scope, id, props) {
super(scope, id, props);
const { table } = props;
// Create the API
this.api = new sst.Api(this, "Api", {
customDomain: scope.stage === "prod" ? "<http://api.royalceramicsn.com|api.royalceramicsn.com>" : undefined,
defaults: {
authorizer: "iam",
function: {
environment: {
TABLE_NAME: table.tableName,
STRIPE_SECRET_KEY: process.env.STRIPE_SECRET_KEY ? process.env.STRIPE_SECRET_KEY : '',
},
},
},
routes: {
"POST /admin/notes": "src/admin/user_notes/create.main",
"GET /admin/notes/{id}": "src/admin/user_notes/get.main",
"GET /admin/notes": "src/admin/user_notes/list.main",
"PUT /admin/notes/{id}": "src/admin/user_notes/update.main",
"DELETE /admin/notes/{id}": "src/admin/user_notes/delete.main",
"POST /billing": "src/billing.main",
},
});
// Allow the API to access the table
this.api.attachPermissions([table]);
// Show the API endpoint in the output
this.addOutputs({
ApiEndpoint: this.api.customDomainUrl || this.api.url,
});
}
}
thdxr
05/06/2022, 3:43 PMSelo
05/06/2022, 3:44 PMFrank
Selo
05/11/2022, 7:32 PMFrank