Hey Guys any idea on how can we put some initial d...
# help
m
Hey Guys any idea on how can we put some initial data in dynamodb during CDK deployment? It will be so much better if we can update/reset data in db when let say DB construct is updated.. etc. (don't want to run this script on every deployment if there is no change to db or the data) using aws cli for now using dynamodb update query.
t
I've done things like this with CDK custom resource definition. It's basically a lambda that's called during deployment
f
hmm.. seems like we should think about DB seeding/migration in SST 🤔
@thdxr in the custom resource, do you track which migrations have been run, and only run the ones that are newly added?
t
Correct, I keep track of successfully run migrations in the database itself
f
Ah makes sense!
@Mr.9715 If SST had something like:
Copy code
new sst.Run(this, "DBMigration", {
  script: "src/migrations/script.main",
});
It basically creates a Lambda function with the script code and a CloudFormation custom resource that runs the Lambda function on CloudFormation deployment. More details on how it works here.
Does this help you configure DynamoDB data?
m
Hey @Frank, this looks good.💯. Is there a way to pass a command-line flag to sst start/deploy if in case we want to run the script on successive deployment or when DB is updated/ needs reset.