Michael Wolfenden
01/25/2022, 6:09 AMFrank
const api = new AppSyncApi(this, "Api", {
...,
dataSources: {
ds: { table: myTable },
},
});
api.getDataSource("ds").grantPrincipal(...);
Michael Wolfenden
01/26/2022, 10:01 PMgrantPrincipal
doesn't exist on type BaseDataSource
Michael Wolfenden
01/26/2022, 10:28 PMDynamoDbDataSource
but is a bit gross, but it worked
const likesTableDS = appSyncApi.getDataSource(
  'likeMutation'
 ) as appsync.DynamoDbDataSource
 invariant(likesTableDS)
 likesTableDS.grantPrincipal.addToPrincipalPolicy(
  new iam.PolicyStatement({
   actions: ['dynamodb:UpdateItem'],
   effect: iam.Effect.ALLOW,
   resources: [usersTable.tableArn, tweetsTable.tableArn],
  })
 )
Michael Wolfenden
01/26/2022, 10:30 PMdataSources: {
likeMutation: { tables: [likesTable, usersTable, tweetsTable] }
}
Michael Wolfenden
01/26/2022, 10:30 PM