amplify-cli icon indicating copy to clipboard operation
amplify-cli copied to clipboard

Access amplify generated GSI from Lambda function

Open mnikolic10 opened this issue 4 years ago • 3 comments

Amplify CLI Version

8.3.0

Question

I've added a Lambda function and am able to access GSI of DDB tables where I have explicitly added @index within a model.

For amplify generated GSI, where I use @belongsTo, I can see it propogates a GSI for me. Is it possible to access this index from my Lambda function? If so, how do I proceed?

For more clarity, I'm wanting to access the parent item of an item within one of my DDB tables, so that when I update this item it also updates the parent.

Let me know if you need more information or if any of the above is unclear.

Thanks in advance!

mnikolic10 avatar Nov 14 '22 11:11 mnikolic10

Hey @mnikolic10 :wave: thanks for raising this! From the details you've provided it sounds like calling the GraphQL API using the GSI's query field would be sufficient https://docs.amplify.aws/lib/graphqlapi/graphql-from-nodejs/q/platform/js/#commonjs

Are you looking to interact with DynamoDB directly from your Lambda? If so, direct SDK calls would be the suggestion, however I feel for this use case calling GraphQL directly using a private IAM auth rule would be the recommended path.

josefaidt avatar Nov 14 '22 16:11 josefaidt

I am already using the aws sdk to interact with my tables, ill take a look at the link you mentioned. Thanks for your help!

mnikolic10 avatar Nov 15 '22 10:11 mnikolic10

@mnikolic10 absolutely! If you are also using subscriptions in your frontend app I believe it is also recommended to make changes via GraphQL.

I will close this issue for now, however please feel free to reply back and we can re-open to continue investigating!

josefaidt avatar Nov 15 '22 16:11 josefaidt