amplify-cli: Ability to add DynamoDB triggers via amplify add function
Is your feature request related to a problem? Please describe. I’ve created a graphql api backend and declared tables in my schema using @model. I would like to create a function to populate a field on the table on insert. Attempting this caused the following error:
There are no DynamoDB resources configured in your project currently
Describe the solution you’d like I’d like amplify to recognize the dynamoDB tables creates via the graphql schema so that I can add lambda function “triggers”.
Describe alternatives you’ve considered I’ll probably do the work on the front end for now.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 51
- Comments: 30 (5 by maintainers)
Is it possible to make an existing function trigger from DynamoDB with
amplify function update, or can I only do that when I create the function?It would be nice if we could have an
@triggerdirective that works like the@functiondirective.Also have this issue. It seems like creating a Lambda function doesn’t recognize the DynamoDB backend created when using
amplify add apiand you choosegraphql.I would second this request… the ability to configure a lambda to trigger based on Dynamo or Cognito or even SQS.
Hey guys, we released this functionality in the latest version of our CLI - 4.16.1. This was merged as a part of this PR - #2463
Update: If the DynamoDB created by
amplify add apiwould be displayed inamplify-meta.jsonyou could access it via the environment variables in the CloudFormation template (similar to howenvand<you-appsync-api>GraphQLAPIIdOutputis accessed in"Parameters").Until that is the case or until you can choose your existing DynamoDB in the Amplify prompts, here is a manual workaround:
Add you parameters (note AVOID COMMITTING THESE TO GIT, or use fake):
Append the policies manually which would be automatically generated for you:
If you used fake parameters, visit your Lambda function in your Lambda console and add the environment variables (
storage<your-db-name>dynamoNameandstorage<your-db-name>dynamoArn) after you pushed the function (it will overwrite any existing variables). That way you can use you DynamoDB as if you had chosenCRUD function for Amazon DynamoDB table (Integration with Amazon API Gateway and Amazon DynamoDB)inamplify add auth.Steps to reproduce:
Have configured API backed by DynamoDB.
Any updates to this? It seems that the tutorial in the announcement is using two tables - one from the
graphql.schemawith@modeldirective and one from thestoragehttps://aws.amazon.com/de/blogs/mobile/amplify-framework-adds-support-for-aws-lambda-functions-and-amazon-dynamodb-custom-indexes-in-graphql-schemas/#
I think you can add the function then go to the DynamoDB table, go to “Triggers” and click “Create trigger” and add the trigger manually to that existing function.
any updates on this? the cli will only generates policies for the appsync, we need the policies for dynamodb like this:
@Buder This is actually something I am looking into right now, you can add a trigger through the DynamoDB console and create a lambda function or use an existing lambda function for that trigger, choosing the create a new function didn’t work for me so I created one manually and I needed to add the correct policies to that function’s role so that it will work with the dynamo trigger (dynamo will tell you what roles to add).