export const meta = {
  title: `Share single environment`,
  description: `Learn the recommended workflow for multiple team members sharing a single Amplify environment.`,
};

You have two independent environments (`main` & `dev`) in the cloud and have corresponding Git branches with your Amplify backend infrastructure code on Git. Suppose all team members want to work on the same Amplify project and push backend related changes to the same `dev` environment to test their changes. Each team member would run the following:

```bash
cd <project-dir>
amplify init
```

<Callout warning>

Ensure the root of your project has the `amplify` folder set up in order to be able to re-use existing environments.

If the **team-provider-info.json** file is missing:

1. Backup and remove the `amplify` folder
2. Pull the environment from the root of your project folder using the `amplify pull --appId <app-id> --envName <env-name>` command displayed in the Amplify Console for your application

</Callout>

```console
Do you want to use an existing environment? Yes
Choose the environment you would like to use:
❯ dev
main
# The rest of init steps
# amplify add/update 
amplify push
```

Since the team is sharing the same `dev` backend, periodically team members would need to pull in changes which their team members pushed for the `dev` environment to be in sync. Let's pull in the changes from the `dev` branch & environment.

```bash
amplify pull
```

## Sharing projects within the team

<Callout warning>

Team members will only be able to push to a stack only if they have the [correct credentials (access key/secret keys)](https://docs.amplify.aws/cli/start/install#pre-requisites-for-installation) to do so.

</Callout>

Inside the `amplify` directory file-structure, you will observe a **team-provider-info.json** file which contains a structure similar to the following:

```json
{
  "dev": {
    "awscloudformation": {
      "AuthRoleName": "multenvtest-20181115101929-authRole",
      "UnauthRoleArn": "arn:aws:iam::132393967379:role/multenvtest-20181115101929-unauthRole",
      "AuthRoleArn": "arn:aws:iam::132393967379:role/multenvtest-20181115101929-authRole",
      "Region": "us-east-1",
      "DeploymentBucketName": "multenvtest-20181115101929-deployment",
      "UnauthRoleName": "multenvtest-20181115101929-unauthRole",
      "StackName": "multenvtest-20181115101929",
      "StackId": "arn:aws:cloudformation:us-east-1:132393967379:stack/multenvtest-20181115101929/fc7b1010-e902-11e8-a9bd-50fae97e0835"
    }
  },
  "main": {
    "awscloudformation": {
      "AuthRoleName": "multenvtest-20181115102119-authRole",
      "UnauthRoleArn": "arn:aws:iam::345090917734:role/multenvtest-20181115102119-unauthRole",
      "AuthRoleArn": "arn:aws:iam::345090917734:role/multenvtest-20181115102119-authRole",
      "Region": "us-east-1",
      "DeploymentBucketName": "multenvtest-20181115102119-deployment",
      "UnauthRoleName": "multenvtest-20181115102119-unauthRole",
      "StackName": "multenvtest-20181115102119",
      "StackId": "arn:aws:cloudformation:us-east-1:345090917734:stack/multenvtest-20181115102119/3e907b70-e903-11e8-a18b-503acac41e61"
    }
  }
}
```

This file is to be shared between team members, so that they have the ability to push/provision resources to the same CloudFormation stack and that way teams can work in a push/pull way and can always be in sync with the latest state of the project in the cloud.

If you want to share a project publicly and open source your serverless infrastructure, you should remove or put the `amplify/team-provider-info.json` file in the `.gitignore` file.
