aws-cdk icon indicating copy to clipboard operation
aws-cdk copied to clipboard

Add grant methods to Appsync's GraphqlApi

Open andreascasen opened this issue 6 years ago • 1 comments

Adding the following methods to the GraphQLApi class:

  • grantQuery(grantable, fields)
  • grantMutation(grantable, fields)
  • grantSubscription(grantable, fields)

Use Case

Setting up IAM access for an AppSync API is a bit complex at the moment and requires code constructs that are easy to break or forget to update. It would be great if, similar to what is done in constructs like DynamoDB or S3 buckets, we could simply grant query, mutation or subscription access to grantable AWS resources, like a lambda. This would take away the need to manually set up policies where each field or type in the schema needs to be specified separately, etc.

Proposed Solution

const appSyncApi: GraphQLApi = new GraphQLApi(...)
const readerLambda: Function = new Function(....)
// Grant readerLamba access to all Query operations by providing '*' as a field
appSyncApi.grantQuery(readerLambda, ['*']) 

const articleWriterLambda: Function = new Function(...)
// Grant articleWriterLambda access to Mutation operations only on the provided fields
appSyncApi.grantMutation(articleWriterLambda, ['article', 'articles'])

Other

  • [ ] :wave: I may be able to implement this feature request
  • [ ] :warning: This feature might incur a breaking change

This is a :rocket: Feature Request

andreascasen avatar May 08 '20 13:05 andreascasen

Grant methods added in #8993.

BryanPan342 avatar Jul 24 '20 16:07 BryanPan342