简体   繁体   中英

How to access dynamodb generated by graphql model in lambda function and perform operations?

I am very new to aws and I am having a hard time understanding the process between lambda function and the dynamoDB. I followed this documentation .

According to the documentaion this trigger is used to get the records of the tables from dynamodb.

exports.handler = function (event, context) {
  console.log(JSON.stringify(event, null, 2));
  event.Records.forEach((record) => {
    console.log(record.eventID);
    console.log(record.eventName);
    console.log('DynamoDB Record: %j', record.dynamodb);
  });
  context.done(null, 'Successfully processed DynamoDB record');
};

And the event is coming from the 'event.json' file. Which is this:

{
  "key1": "value1",
  "key2": "value2",
  "key3": "value3"
}

What I want to accomplished is to retrieve and update the data of my dynamodb 'User' table which is from this graphql model.

type User @model @auth(rules: [{allow: owner, operations: [create, update]}]){
    id: ID!
    coins: Int
}

Not sure amplify docs is the best one to use for learning Lambda. Second, why do you want to use GraphQL to perform CRUD operations on an Amazon DynamoDB table from within a Lambda function. There are other ways such as using the JavaScript SDK from within a Lambda function as discussed here in the JavaScript Developer Guide :

Creating scheduled events to execute AWS Lambda functions

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