Suppose your team decides to use AWS Amplify but each developer in your team has got separate AWS accounts which don’t have access to each other’s resources. In Amplify, we create different environments but mostly in Amplify’s documentation and elsewhere, the scenario normally implies that different developers are AWS users under the same AWS accounts, so they have access to the resources different environments generate.
Now how to deal with this when each developer in your team has a separate AWS account, which has no access to the others?
This post is going to describe in detail that we will have a different AWS Amplify environment setup for each of the developers. These developers are going to work in their own environment separately, considering its their own sandbox, while they will push these changes to their AWS accounts using AWS profiles setup on their own machine.
Remember, an environment setup with an AWS Profile is always going to link to that environment. It is not possible later to push to a given environment with a different AWS profile than with which it was setup in the first place initially.
This post assumes that you have the following setup already:
- Amplify CLI installed.
- An AWS Profile with permissions to deploy to your AWS account for each developer
First time setup by developer # 1
We will refer to developer # 1 as
Now considering that you have an Amplify app setup in a Git repository, we start with the first developer who is going to create the Amplify app and its first environment:
Choose defaults or as preferred, and give the environment a name of your choosing. We will call this environment
You will also be prompted for using an AWS Profile. Provide a profile with the appropriate access to perform Amplify operations in your AWS Account.
Then, for the sake of an example, we are going to create a service in Amplify, Authentication, which is going to create the necessary resources in AWS Cognito. Then we commit and push the changes to the branch(say master):
amplify add auth amplify push git add --all && git commit -m "Initial Commit" && git push origin master
Developer # 2 setup
We will refer to this developer as
Now the second developer, who has a completely separate AWS account, is going to pull these changes:
git pull origin master
And then she is going to create a new Amplify environment:
Choose a new environment to create and name it something. We call it developerBeta:
? Do you want to use an existing environment? No ? Enter a name for the environment developerBeta
IMPORTANT: Now this is where the magic happens. Here developerBeta is going to provide an AWS profile for their own AWS account, which will link this
developerBeta environment with this developer’s AWS account. Only this developer can then push this Amplify environment to this account which makes this environment exclusive for this developer.
Now if you check the AWS CloudFormation, Amplify and Cognito online consoles, you are going to see that an environment exactly the same as the one created by
developerAlpha is now created for
developerBeta‘s account. Hence, you have successfully achieved a separate sandbox for each of the developers so they can independently tweak their own environments.
This way, each developer’s AWS account is now exclusively linked to an Amplify environment.
How to merge changes from one environment to another environment
Now let’s say
developerBeta has added a new api to the Amplify app using
amplify add api and
developerAlpha wants to merge it in their environment. He would simply need to do this:
git pull origin master amplify env checkout developerAlpha amplify push
This is going to merge the changes from the developerBeta environment to
developerAlpha environment. Bear in mind that this is not going to create the
developerBeta environment in
developerAlpha‘s account; it is only going to create the API resources in
the only drawback of this approach is that every developer will need to keep a separate environment as long as they are working on the same app. This might be less ideal for many teams. If you want to use the same environments for all developers while having different AWS accounts, check out this post.
In this post we learnt that we can create separate AWS Amplify environments for developers with separate AWS accounts using their own AWS profiles located on their local machines. You also learnt how to merge changes from one environment to another in the case of a one developer adding something new to their environment