Muhammad Ali
10/27/2021, 7:02 PM<http://sst.App|sst.App>, name, props
and rest would be generic. I am planning to use props
to pass in which methods to create (get
, post
etc) since the name would be same and then use props.tables
to attach permissions to specific tables (dynamodb).
Right now my props interface looksl ike this
interface MyApiProps extends sst.StackProps {
readonly authorizer: apigAuthorizers.HttpUserPoolAuthorizer;
readonly table?: sst.Table;
readonly get: boolean;
}
The problem i am having is on table?
property. given that its "optional" it can exist or not. Now when i try to make a custom prop by this code
new MyApiStack(app, "heartbeat", {authType: sst.ApiAuthorizationType.NONE, get: true});
I get an error on _this_.api.attachPermissions([props?.table as sst.Table]);
in my MyApiStack
class which is generalizing all this. The error that i get is "The specified permissions are not supported".
This error is easily fixed if i pass a table object in MyApiStack(app, "myapi", {authType: sst.ApiAuthorizationType.NONE, get: true, table: myTable});
But I want to find a way where i could skip passing a table object and based on object type (null etc) i avoid attaching permissions. I have already tried this code but it didn;t work
if (props?.table !== null) {
this.api.attachPermissions([props?.table as sst.Table]);
}
thdxr
10/27/2021, 7:06 PMas
thdxr
10/27/2021, 7:06 PMthdxr
10/27/2021, 7:06 PMif (props.table)
this.api.attachPermissions([props.table])
thdxr
10/27/2021, 7:07 PMif
statementthdxr
10/27/2021, 7:07 PMthdxr
10/27/2021, 7:07 PMthdxr
10/27/2021, 7:08 PMconstructor(app: <http://sst.App|sst.App>, name: string, props: MyStackprops) {
super(this, name)
}
You don't have to pass sst.StackProps through to superthdxr
10/27/2021, 7:09 PMsst.Api
basicallyMuhammad Ali
10/27/2021, 7:20 PMAlso in this scenario you might want to be making a generic cdk.Construct instead of a stack. You're kind of making your ownRight now my ApiStack has following signaturebasicallysst.Api
export default class APIStack extends sst.Stack {
constructor(scope: <http://sst.App|sst.App>, name: string, props?: MyCustomProps) {
super(scope, id, props)
// setup api
// add permissions
// add outputs
}
}