简体   繁体   中英

AWS Appsync Lambda Custom Resolver for mutation

I'm complete newbie to AWS. I have appsync models, queries and mutations created by amplify and use DynamoDB. I need to add new timestamp field to DynamoDB in case one specific field has been updated. The only way I found should be Lambda function and use this function as Custom Resolver for mutation UpdateTask. So I created it (it basically just checks if the specific field has been updated and if so, it will set updateXY to current timestamp. I return the changed object). The problem is if I do update no change happens in DynamoDB and no error is returned from Appsync. Can anyone help me, please?

AppSync works by mapping fields in a GraphQL selection set to resolvers that do something with them. If you've overwritten the default resolver, then you aren't talking to DynamoDB anymore. Returning the value without saving/reading anything from DynamoDB won't have the effect you want. Instead, you'll want to interact with DynamoDB from your Lambda resolver.

For an example of a NodeJS-based Lambda resolver that interacts with DynamoDB directly, checkout this blog:

GraphQL API using Serverless + AWS AppSync + DynamoDB + Lambda resolvers + Cognito. [Part 3] . Note in particular how the functions include DynamoDB utilities:

const { insertOrReplace } = require('./../../util/dynamo/operations');

etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM