Global Secondary Indexes in AppSync Schemas (with DynamoDB)

46 Views Asked by At

I am creating my AppSync GraphQL schema (with DynamoDB). Here is my current model:

input AMPLIFY {
  globalAuthRule: AuthRule = { allow: public }
} # FOR TESTING ONLY!
type Post
  @model {
  id: ID! @primaryKey(sortKeyFields: ["sk"])
  sk: String!
  title: String!
  featuredPost: String
}

On the base table i want id to be the primary key with the sort key being sk, as seen.

However, I want a global secondary index with the primary key being featuredPost and sort key being title.

  • How would I add this to the schema? (AI answers are very inconsistent, and I cant find anything in the AWS Docs)
  • Does any reference to a GSI even need to be added to the schema?
1

There are 1 best solutions below

1
Leeroy Hannigan On

You add the index using the console.

Then in your resolver you explicitly tell it which index to use to make that request. Your schema remains unchanged.

More information here