dynamodb icon indicating copy to clipboard operation
dynamodb copied to clipboard

How to scan data from existing table

Open sandesh-bhoir opened this issue 4 years ago • 1 comments

I have a user table already defined, I just need to access its data using scan.

import * as dynamo from 'dynamodb';
async fetchUser(): Promise<any> {
        try {
            dynamo.AWS.config.update({ accessKeyId: process.env.ACCESS_KEY_ID, secretAccessKey: process.env.SECRET_KEY, region: process.env.REGION });
            const user = dynamo.define('User', {
                hashKey: 'email',
                tableName: 'user'
            });
            return await user.scan()
                .limit(10)
                .exec();
        } catch (error) {
            throw error;
        }
    }

I'm not getting any data, am I doing anything wrong here. There is nothing documented for fetching data from existing table. Kindly assist.......!!

sandesh-bhoir avatar May 24 '21 20:05 sandesh-bhoir

return await user
  .scan()
  .limit(10)
  .exec()
  .promise();

steveluscher avatar Jan 20 '23 05:01 steveluscher