:wave: When adding a DynamoDB data source to an Ap...
# help
m
👋 When adding a DynamoDB data source to an AppSyncApi, under the covers a role is created that gives access to that particular table. Is this anyway to add additional permissions to this role. In my case I have a request template that modifies multiple tables in a single transaction so I need UpdateItem permissions added to the role for multiple tables.
f
Hey @Michael Wolfenden, try this
Copy code
const api = new AppSyncApi(this, "Api", {
  ...,
  dataSources: {
    ds: { table: myTable },
  },
});

api.getDataSource("ds").grantPrincipal(...);
m
grantPrincipal
doesn't exist on type
BaseDataSource
I has to cast as
DynamoDbDataSource
but is a bit gross, but it worked
Copy code
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],
    })
  )
Would be nice to allow multiples tables in a datasource
Copy code
dataSources: {
    likeMutation: { tables: [likesTable, usersTable, tweetsTable] }
}
Thanks for you help though .. much appreciated