question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to update/query/scan in DynamoDB using Amplify?

See original GitHub issue

I would like to update a field in my DynamoDB table called ‘AppTable’ using the AWS-Amplify methods that were generated when I created the corresponding CRUD cloud-api (e.g. PUT, GET, POST, DELETE).

These few API methods reside in awsmobilejs/backend/cloud-api/AppTable/app.js, but they are not comprehensive enough!

I can simply use API.put to add to this table. e.g:

apiResponse = API.put('AppTableCRUD', path, body)


body: {
    "uploaderBool": true,
    "userId": 'user1',
    "itemId": '10005',
    "Username": "first_app_user",
    "Email": "user@myapp.com",
    "NumberList": 
       [
        "7.9",
        "5.7",
        "3.4",
        "4.9"
       ],
    "AverageNumber":[
        "5.5"
       ],
     }
    }

What i want to do, is update the NumberList field with a function in my react-native app, count how many numbers in the list on DynamoDB, then calculate/write an updated number called AverageNumber.

If i use a current API.put method i have to put in this ENTIRE body everytime (this list could be hundreds of thousand of entries so Get, then Put with a single update is absurd).

How do you use the .scan(), .query() and .update() method that DynamoDB has with Amplify?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:18 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
elorzafecommented, Jan 19, 2019

Hi @chai86, I created graphql api using aws-amplify-cli with this app code (react web)

import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';
import Amplify, { API, graphqlOperation } from 'aws-amplify';
import { withAuthenticator } from "aws-amplify-react";
import config from './aws-exports';
import { createVideo } from "./graphql/mutations";

Amplify.configure(config);

class App extends Component {

  CreateVideo = async () => {

    const newVideoInfo = {
      videoIdInt: 12345,
      videoName: "sheeran-moon",
      videoUploader: "ed",
      videoUploadedAt: "tonight",
      videoLength: 85,
      numberList: [7, 8, 9],
      shareLink: "www.voda.com"
    }

    try {
      await API.graphql(graphqlOperation(createVideo, { input: newVideoInfo }))
      console.log('User successfully created!!')
    }
    catch (err) {
      console.log('create user error: ', err)
    }

  }

  render() {
    return (
      <div >
        <button
          onClick={this.CreateVideo}
        >Add user</button>
      </div>

    );
  }


}

export default withAuthenticator(App, true);

it seems that input attribute is missing so it should be like this await API.graphql(graphqlOperation(createVideo, { input: newVideoInfo }))

1reaction
elorzafecommented, Jan 21, 2019

@chai86 I am glad it works! 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

Functions - Integrating DynamoDB with Lambda - JavaScript
How to integrate a DynamoDB table with a Lambda function - JavaScript - AWS Amplify Docs.
Read more >
Tutorial: DynamoDB Transaction Resolvers - AWS AppSync
Read records from one or more tables in a single query. Write records in transaction to one or more tables in an all-or-nothing...
Read more >
Working with Data in DynamoDB from React with AWS Amplify
Full Amplify video tutorial series -- https://www.youtube.com/playlist?list=PLmexTtcbIn_hvPcUm3oAufCtH7dwNAC-gIf you want to add data to ...
Read more >
DynamoDB Table Designs for AWS Amplify - YouTube
AWS Amplify with Amazon DynamoDB Single Table and Direct AWS Lambda Resolvers with Rick Houlihan. Serverless Land. Serverless Land.
Read more >
Create a REST API Integrated with Amazon DynamoDB
This video will demonstrate how to easily create a REST API integrated with Amazon DynamoDB using AWS Amplify and how to consume it...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found