Hello folks 😎, here i want to share an interesting story with you all about the AWS congito user pools. There are some situation where we want to create different environments for our applications like dev, test & prod. There are multiple team working on a single project.
So the story is that we are working on a large project and we are using AWS Cognito for the authentication service. Now we have to separate all user environments for our development team and production team. earlier we are using same database and user pools for dev and prod.
There is no clear documentation for AWS amplify on websites. If we found it then it's very confusing for beginner to implement those thing in a real production application. So that i decided to write this article for all of those who need to create different environments in AWS amplify for development & production teams.
How to create or add team environments in existing app using amplify.
So here in my case i have already one user pool added for authentication which i run for both prod and dev. Now i need separate user pools & add another for dev. I keep old one as it is, which is for prod. No need to touch existing environments.
Make sure you have installed amplify CLI by running following command:
npm i -g @aws-amplify/cli
And configure user by running amplify configure
or see this instruction
If you want to see your app environments just type this command to know status
amplify status
This prints out app environment i have created earlier named Auth, if you have not created before don't worry.
If you want to see operational commands of AWS Amplify just type
amplify env
It print all command with information in console.
Setting up new team environment
To create a new environment in an existing AWS Amplify project, you can run the amplify init
command & you will now have the option to initialize a new environment in the current working project.
Let’s first look at how to create & manage multiple local Amplify environments. In this example, we’ll see how to add & test out new features without affecting our original / main Amplify project.
$ amplify init? Enter a name for the environment: prod
// Provide AWS Profile info
// Add amplify categories using `amplify add <category>`
Once you have your ‘prod’ env setup, set up a ‘dev’ environment in your Amplify project (which would be based on your ‘prod’ environment), and then walk through the following steps to create a corresponding git branch for it.
$ amplify env add
? Do you want to use an existing environment? No
? Enter a name for the environment dev
// Provide AWS Profile info
This will set up another environment for the project in the cloud. The backend-configs and resources are now cloned from the ‘prod’ environment.
Run amplify push
to provision all the AWS resources for your new environment (dev).
amplify push
This will update team-provider-info.json
where you can see previous and newly created environment information.
To use any of this environment which we have created just use command given below. Amplify uses same flow as git.
amplify checkout <environment name>
That's it this will switch environments in your projects whenever you want to switch and use property from it.
If i miss something here then please let me know in comment section.