Brett Fieber
02/17/2022, 8:07 PMStorageStack
I'm creating an sst.Table construct that references an existing table, like so:
this.myDataTable = new sst.Table(this, 'MyData', {
dynamodbTable: dynamodb.Table.fromTableArn(this, 'MyDataTable', `arn:aws:dynamodb:${scope.region}:${scope.account}:table/${scope.stage}-my-data`)
})
Then in my ApiStack
I'm granting the Api permissions, like so:
this.api.attachPermissions([myDataTable])
All is well.. Hurray. But...
If I want to query from a global secondary index, such as GSI0
, I get permission denied.
Do I need to create an additional sst.Table construct pointing to that index? such as:
this.myDataGSITable = new sst.Table(this, 'MyDataGSI', {
dynamodbTable: dynamodb.Table.fromTableArn(this, 'MyDataTableGSI', `arn:aws:dynamodb:${scope.region}:${scope.account}:table/${scope.stage}-my-data/index/GSI0`)
})
Or is there a more appropriate method to grant access to the API?Ashishkumar Pandey
02/17/2022, 9:05 PMAshishkumar Pandey
02/17/2022, 9:06 PMDerek Kershner
02/17/2022, 10:25 PMfromTableArn
you need to use fromTableAttributes
and specify that the table has secondary indexes.Brett Fieber
02/17/2022, 10:48 PMBrett Fieber
02/17/2022, 11:46 PMStorageStack
to:
this.myDataGSITable = new sst.Table(this, 'MyDataGSI', {
dynamodbTable: dynamodb.Table.fromTableAttributes(this, 'MyDataTableGSI', {
tableArn: `arn:aws:dynamodb:${scope.region}:${scope.account}:table/${scope.stage}-my-data`),
globalIndexes: ['GSI0']
}
Derek Kershner
02/17/2022, 11:47 PMDerek Kershner
02/17/2022, 11:48 PMBrett Fieber
02/17/2022, 11:49 PMDerek Kershner
02/17/2022, 11:49 PMBrett Fieber
02/17/2022, 11:49 PMDerek Kershner
02/17/2022, 11:50 PMDerek Kershner
02/17/2022, 11:50 PMthis.metadataDynamoTable.grantReadWriteData(postImagesLambda);
with itDerek Kershner
02/17/2022, 11:51 PMBrett Fieber
02/17/2022, 11:51 PMthis.api.attachPermissions([myDataTable])
Derek Kershner
02/17/2022, 11:51 PMBrett Fieber
02/17/2022, 11:56 PMDerek Kershner
02/17/2022, 11:57 PM