0
votes

I have a serverless framework and dynamo db in my local. I am trying to seed data . When i do 'sls offline start', seed data is getting inserted into my local dynamo db. but when i deploy it to aws using 'sls deploy'. i don't see the seed data getting inserted on aws dynamo db.

I am very new to serverless and this is my 1st serverless application and deployment . I am using 'serverless-offline' and 'serverless-dynamo db' .

Below is my configuration on serverless.yml

serverless-offline:
host: 0.0.0.0
  dynamodb:
    start:
      port: 8000
      inMemory: true
      migrate: true 
      seed: true
      convertEmptyValues: true
    seed:
      domain:
        sources:
          - table: ${self:custom.test}
            sources: [seed/test.json]

Above configuration is working good for local setup. When i run sls offline start, everything is working fine. But when i do 'sls deploy' . I don't see seed data in dynamo db tables on aws . Also wanted to know where can i see the json seed data file (test.json) on aws server. Does it automatically gets deployed somewhere?

2
any help please? - Fakeer
i think the seeding functionality is only supported i serverless offline, by dynamo local plugin and its not supposed to work online github.com/99xt/serverless-dynamodb-local - varnit
@varnit : Thanks - Fakeer
Should i post it as answer other users might face the same problem - varnit
yup. Please post it as an answer. - Fakeer

2 Answers

2
votes

The seeding functionality is only supported in serverless offline, by dynamo local plugin and its not supposed to work online github.com/99xt/serverless-dynamodb-local

You can however use cloudformation init function, which will execute a lambda function during the stack creation, you can use it to seed your dynamo db tables.

1
votes

varnit is correct. You can only seed offline with serverless-dynamodb-local. For seeding data in your DynamoDB that is deployed to AWS by serverless there are a few libraries that can help as well if you don't want to do it yourself as varnit suggests.

https://www.npmjs.com/package/serverless-dynamodb-seed

  • This is serverless specific

https://www.npmjs.com/package/aws-cdk-dynamodb-seeder

  • This is more generic