You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey folks 👋 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:
seeding arbitrary data for testing (auth flows, UI rendering, etc.)
seeding preliminary data for environments (base tenant configurations, etc.)
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:
preconfigured clients for interacting with Auth and Data resources
an orchestration mechanism
Getting started, you will be able to create a seed.ts file in your amplify/ directory that exports a function with the SeedFunction type:
// amplify/seed.tsimporttype{SeedFunction}from'@aws-amplify/backend'import{backend}from'./backend'constseed: SeedFunction<typeofbackend>=async({ auth, data })=>{// create a test userconstuser=awaitauth.createUser('testuser','Testpassword1234!')// set the test user on the sessionauth.setCurrentUser(user)// create 10 posts as that userletposts: Schema['Post'][]=[]for(leti=0;i<10;i++){constpost=awaitdata.models.Post.create({title: `post ${i+1}`,authMode: 'userPool'})posts.push(post)}// create an admin userconstadmin=awaitauth.createUser('testadmin','Testpassword1234!',{groups: ['ADMINS']})// use the admin user to update a postauth.setCurrentUser(admin)awaitdata.models.Post.update({id: posts[0].id,title: 'updated title by admin'})}exportdefaultseed
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.
Hey folks 👋 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
The text was updated successfully, but these errors were encountered: