Open antennix opened 1 month ago
Hi @antennix, you can grant a function access to the Data API by following these docs: https://docs.amplify.aws/react/build-a-backend/data/customize-authz/grant-lambda-function-access-to-api/
We are also actively investigating making the experience of configuring the data client in the context of a lambda function a better experience, so any feedback you have there is welcome!
@edwardfoyle Thank you. I understand the current approach to Data (AppSync). I'm hoping that the process of generating GraphQL code will become simpler.
On the other hand, is there an approach for when we want to access the data source (Dynamo) directly?
For example, executing a daily batch via Function (I believe the scheduling feature will be implemented soon: https://github.com/aws-amplify/amplify-backend/issues/1491), and performing specific processing on DynamoDB records.
We could update records through AppSync, but I don't think we can do so without users who are executing Subscriptions noticing. I want to update silently.
Hi, @antennix , I bumped into the same issue a couple of days ago when trying to pass the dynamoDB table name to my lambda hander as an env variable, and I did exact the same thing as you mentioned in the description section, which caused a circular dependencies
issue.
Then, I joined in a discussion in another similar open issue #2554, where we believe this could be some sort of bug. But fortunately, other great devs came up with some workarounds, which I already tested in my case and they worked just fine. And I hope they could work for you too. Good luck!
@MyNameIsTakenOMG Thank you. I think the Lambda custom resource that indirectly retrieves the resource name is a very good idea.
Marking as feature request to provide Data parameters such as table name and arn as environment variables.
Environment information
Description
Is it possible for a Function to receive the Endpoint of Data, or the name and ARN of Datasources like DynamoDB?
For example, with Storage, you can use the "access" property in the defineStorage function to grant read and write permissions to a Function. https://docs.amplify.aws/react/build-a-backend/functions/grant-access-to-other-resources/
However, a similar approach cannot be used with defineData as it's not possible to specify properties.
It is possible to directly set values for an already created function in backend.ts using CDK, but if you're also using defineFunction for resolvers against Data, I think an error would occur due to circular reference, as the reference order would be resolverFunction → Data → thisFunction.
Is there a good solution?