Open josefaidt opened 8 months ago
this is worth noting for the auth client https://github.com/aws-amplify/amplify-js/blob/main/packages/aws-amplify/src/adapterCore/authProvidersFactories/cognito/createUserPoolsTokenProvider.ts#L21-L37
Is there any ETA on data seeding capabilities or current examples/best practices for data seeding in Amplify Gen 2?
@josefaidt Seconding @AnaCoda comment. This or a temporary workaround would be really useful.
I think we also need a mechanism to dynamically specify which type of branches should do seeding or if it's only available in sandbox environments.
@josefaidt Seconding @AnaCoda comment. This or a temporary workaround would be really useful.
@ideen1 / @AnaCoda - for non-sandbox environments, you can go to the Data Manager in the console and click "Actions" > "Generate seed data"
@josefaidt I was thinking maybe we could use a createSeedFunction
. That way we can allow customers to pass in a set of patterns, in which we should run the seed logic.
// amplify/seed.ts
import { createSeedFunction } from '@aws-amplify/backend'
import { backend } from './backend'
const seed = createSeedFunction(['feature/*'], async ({ data }) => {
// create 10 posts as that user
let posts: Schema['Post']['type'][] = []
for (let i = 0; i < 10; i++) {
const post = await data.models.Post.create({
title: `post ${i + 1}`,
})
}
})
export default seed
@renebrandel I like where you're headed but I think this would best be handled by something like https://github.com/aws-amplify/amplify-backend/issues/1094
It would also be useful if one could seed data with a specific data set say from a json or js file. - I see this could be potentially done in a loop in the seed function but it might be useful to have a dedicated api for it.
@josefaidt , are there any updates if these seed data capabilities will be coming at some point? Also, in the meantime, are there any resources to how I could do this: "Today, you can use the AWS SDK in conjunction with the Amplify (Gen 2) data client to seed sandbox and branch environments"?
Would be a huge help!
Hey folks :wave: we’ve been thinking about seeding capabilities for the Data and Auth categories, and would love to get your feedback! In our explorations we’ve found seeding can be applied to two primary use cases:
Today, you can use the AWS SDK in conjunction with the Amplify (Gen 2) data client to seed sandbox and branch environments, however this involves writing the scripts and manually invoking at some point in time. This can be tedious to author, test, and orchestrate, where we would like to provide functionality out of the box to help make this easier.
Thoughts
At a high level we’re thinking of a TypeScript file that exports a seed function with a new command to invoke,
amplify seed [path-to-file]
. The thought highlights two notable attributes of the intended experience:Getting started, you will be able to create a
seed.ts
file in youramplify/
directory that exports a function with theSeedFunction
type:By providing seed via a TypeScript file, this would also enable the use of flat files and create complex data model relationships. For seeding preliminary data to a new environment, we can provide some mechanism to ensure seed only runs once for that environment — this way you do not need to juggle
amplify seed
in your buildspec/amplify.yml
file.Acknowledgements