serverless-dynamodb-local icon indicating copy to clipboard operation
serverless-dynamodb-local copied to clipboard

Seed .js files?

Open spacesuitdiver opened this issue 7 years ago • 1 comments

Can we seed .js files so we can make data up? That'd be super mega awesome.

spacesuitdiver avatar Apr 20 '17 01:04 spacesuitdiver

Just wanted to leave a note here to say that this is possible.

seed/test.js

const faker = require('faker');

const seedUsers = (userCount = 10) => {
  const dataRows = [];

  for (let userIndex = 0; userIndex < userCount; userIndex += 1) {
    const user = faker.helpers.userCard();

    dataRows.push({
      Id: faker.random.uuid(),
      Label: faker.random.word(),
      name: user.name,
      email: user.email,
    });
  }

  return dataRows;
};

module.exports = seedUsers();

Simply set test.js as one of the sources in your serverless configuration:

custom:
  dynamodb:
    seed:
      test:
        sources:
          - table: TestTable
            sources: [./seed/test.js]

kelchm avatar Dec 20 '19 21:12 kelchm