Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not possible to configure ddb Lambda trigger if GraphQL allows any function #1740

Open
OperationalFallacy opened this issue Jul 12, 2024 · 3 comments
Assignees
Labels
feature-request New feature or request needs-product-input Needs non-technical requirements or direction to proceed

Comments

@OperationalFallacy
Copy link

Environment information

all latest

Description

Here's a use case for DDB lambda trigger with access to graphql. The lambda will process records and update state in the model with GraphQL mutation (careful with the updates since it can cause circular trigger).

Possible to achieve with this example https://docs.amplify.aws/react/build-a-backend/functions/examples/dynamo-db-stream/

However, it currently not possible to deploy, if model's auth includes at least one function (test1 function here) - then adding event source will break with circular dependency problem.

This is because the functions are added into own nested stack, which creates a dependency on data nested stack, which creates a circular dependency when these stacks referenced for event source.

const backend = defineBackend({
  auth,
  data,
  docUploaderFunction,
  test1,
});

const eventSource = new DynamoEventSource(
  backend.data.resources.tables["Todo"],
  {
    startingPosition: StartingPosition.LATEST,
    batchSize: 5,
  }
);

backend.docUploaderFunction.resources.lambda.addEventSource(eventSource);
amp sandbox
...
The CloudFormation deployment has failed.
Caused By: ❌ Deployment failed: Error [ValidationError]: Circular dependency between resources: [data7552DF31, function1351588B]

I think this is a legit bug.

Related: #1594

@OperationalFallacy OperationalFallacy added the pending-triage Incoming issues that need categorization label Jul 12, 2024
@ykethan
Copy link
Member

ykethan commented Jul 17, 2024

Hey, thank you for reaching out. The issue appear to be similar to #1552, #1723.

Refer to the comments providing examples in creating a Lambda event source that mitigates the issue.
#1552 (comment)
#1723 (comment)

Marking this as feature request to further evaluate the nested stacks being created.

@ykethan ykethan added feature-request New feature or request needs-product-input Needs non-technical requirements or direction to proceed and removed pending-triage Incoming issues that need categorization labels Jul 17, 2024
@OperationalFallacy
Copy link
Author

OperationalFallacy commented Jul 17, 2024

Those are the example for external integrations, I think. I got it working as well, no problem there.

The case I'm describing is what Amplify published in the document page linked.

  1. There is a Lambda function managed by Amplify (it sets everything up automatically to access graphql with a client)
  2. Lambda function have permissions to use AppSync, again via .authorization((allow) => [ allow.resource(LambdaFunction)])

This Lambda gets invoked by DDB stream, so it can work with graph client and model types = profit

In other words, I can't work with GraphQL in Lambda functions managed by Amplify, if I want this function invoked by DDB stream.

And even if I use sdk to access tables directly, the event sourcing still breaks, if there is one function with authorization on scheme.

@ykethan
Copy link
Member

ykethan commented Nov 27, 2024

With the latest release, the defineFunction now supports resourceGroupName property which should allow grouping the function with other categories this should help with the breaking the circular dependency between the stacks. Created a sample application providing with similar use case with event source as DDB stream on a function.
https://github.com/ykethan/amplify-gen2-samples/tree/main/circular-dependency-rg
But do note, setting this `resourceGroupName property will recreate the lambda function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request New feature or request needs-product-input Needs non-technical requirements or direction to proceed
Projects
None yet
Development

No branches or pull requests

3 participants