Backend Environments
October 13, 2022 ยท View on GitHub
This folder contains a list of pre-built Amplify backends for use with manual & automated testing.
Zero Configuration
These environments rely on @aws-amplify/cli@latest (v6.4.0+) to work.
Using an Existing Backend Environment
For manual and end-to-end testing, example applications will use a particular backend environment by pulling the aws-exports.js file from the environments/{BACKEND_ENVIRONMENT}/src directory. To use an existing backend environment, please use the following instructions.
External Contributors
- You will need an AWS account and the Amplify CLI installed and configured to use your AWS profile. Follow the "Amplify Getting Started: Prerequisites" tutorial to set up your AWS account and configure the Amplify CLI tool. Note: Only follow the "Prerequisites" tutorial. Do not move on to the "Set up fullstack project" tutorial.
- In a terminal,
cdinto the environment you want to use for testing your changes and initialize the environment using your own AWS account withamplify init. For example:cd environments/auth-with-email && amplify init- You will be asked a couple of questions by the
amplifyinteractive prompt. ForEnter a name for the environmentandChoose your default editor, you can answer them as you prefer. - For
Select the authentication method you want to use, selectAWS profileand choose the profile you configured in step 1.
- You will be asked a couple of questions by the
- Run the following command to push up the local environment configuration to the environment you just initialized in your AWS account:
amplify push- Answer
Yesto the promptAre you sure you want to continue?. This command may take several minutes to complete.
- Answer
- Run the following command to open the Amplify Admin UI to see your environment:
amplify console- Answer
Amplify admin UIto the promptWhich site do you want to open?. Your environment is now configured for local testing. Note: Following the above steps may generate some changes in the environment's directory. You are safe togit checkoutthose changes.
- Answer
Creating a Backend Environment
When an existing backend doesn't match your needs (or requires changes), you can create a new backend via the Amplify Admin or the Amplify CLI.
With Admin UI
-
Open https://console.aws.amazon.com/amplify/home?region=us-east-1#/ and click "All apps":

-
Under "New app", click "Create app backend":

-
Enter a descriptive name for this environment (e.g.
auth-with-username) and click "Confirm deployment":
-
Click "Open Admin UI":

-
Enable your backend categories.
For auth-with-username, we clicked "Enable authentication":

-
Configure your category or categories:
For auth-with-username, we added the
Usernamelogin mechanism:
-
Click "Save and deploy" then wait a few minutes:

-
Finally, you'll have "Local setup instructions" in the top-right:
amplify pull --appId dbffpda9986p --envName staging
-
Next, in your terminal create a folder for this environment:
cd environments # Change change this next line to match your app name mkdir auth-with-username cd $_ -
Run the
amplify pull ...command from Admin UI:amplify pull --appId dbffpda9986p --envName staging --yes(Passing
--yeswill skipamplify initprops and select defaults automatically)
๐ You now have a local amplify & src/aws-exports.js environment!
Committing a Backend Environment
After creating a new backend environment for local development, it can be useful to commit the configuration for future use in testing or collaboration.
-
First, create a
README.mdthat describes what makes this backend unique (example) -
Create a
package.jsonfile for the environment with ayarn pullscript that uses the pull command from step 8 above:// environments/auth-with-username/package.json { "private": true, "name": "my-custom-environment", "version": "0.0.1", "scripts": { "pull": "amplify pull --appId dbffpda9986p --envName staging" } }If your backend was created with the Amplify CLI, you'll need to enable Admin UI for it:
-
Within the environment, run
amplify consoleto view the Auth backend. -
Select the backend.
-
Click
Set up admin UI
-
Toggle
Enable admin UI (All environments)toOn. -
Click
Open Admin UI -
Finally, select
Local setup instructionsto get your--appIdand--envName
-
-
Stage all changes in the new environment as you normally would and commit the changes:
# Within environments/my-custom-environment: git add . # This will add `amplify`, `src`, and `.gitignore` generated by `amplify pull` git commit -m "Add my-custom-environment backend"