Search code examples
reactjsamazon-web-servicesaws-amplify

How to create edittable tables with aws amplify and dynamodb


Does anyone know how to make tables editable on reactjs, where the datasource is from a dynamodb table?


Solution

  • You can use the API category in Amplify for this, and have API Gateway run a Lambda that performs your business logic for reading and writing to DynamoDB. The AWS Mobile CLI has this pattern built in:

    $ npm install -g awsmobile-cli
    $ cd my-app
    $ awsmobile init
    $ awsmobile enable cloud-api
    

    Then if you were trying to edit it would probably be a POST using the API category:

    async function postData() { 
        let apiName = 'MyApiName';
        let path = '/path';
        let myInit = { // OPTIONAL
            body: {}, // replace this with attributes you need
            headers: {} // OPTIONAL
        }
        return await API.post(apiName, path, myInit);
    }
    
    postData();
    

    The React Sample on AWSlabs demonstrates this: https://github.com/awslabs/aws-mobile-react-sample