Skip to content
This repository has been archived by the owner on Jul 21, 2022. It is now read-only.

Amplify tips (Environment)

thoell edited this page Dec 16, 2020 · 2 revisions

Creating new environment

NOTE: Creating a sandbox environment should only be done if necessary as the steps necessary are somewhat complicated.

  • amplify init
  • Use existing environment: No
  • AWS profile: Yes
  • Google Web Client ID and secret: Get from team-provider-info.json > dev > categories > auth > kompetansekartlegging > hostedUIProviderCreds
  • amplify push
  • amplify pull (ensures src/aws.exports.js is updated)
  • Update Environment table ID:
    • Go to tables in DynamoDB
    • Find a table from your newly created env. Tables are named: TableType-generatedid-envname, and open this table.
    • Copy the string with the table's generated ID and envname, ie. "abc12356789-myenv"
    • Open helperfunctions.ts > getEnvTableID, and paste the value as return value.
  • Authorize redirect URL:
    • Open Google Developer Console
    • Open Project "Kompetansekartlegging". If this cannot be found, access must be granted by asking drift.
    • Open Credentials > OAuth 2.0 Client IDs > Cognito
    • Add URI: copy one of the existing URI, and change the environment name to yours.
    • Save
  • To make enviroment accessible by others: git secret hide && git push

If the environment is to be set up as a published frontend hosted by Amplify, a further step must be done:

  1. run amplify auth update
  2. "What do you want to do?": Add/Edit signin and signout redirect URIs
  3. "Which redirect signin URI do you want to edit?": Note the existing URIs, copy the link of one and change the environment name with yours.
  4. With none selected, click enter
  5. "Do you want to add redirect URIs?": Y
  6. "Enter your new redirect signin URI": Paste the edited link from step 3, and press enter.
  7. "Do you wish to add another URI?": N
  8. Repeat the same process for redirect signout URIs.
  9. Once all is done, remember to run amplify push

Pulling changes to another environment

For the purposes of this example, imagine you are to pull changes from the dev environment into master.

In theory, and what is recommended from different sources online, the way to do this is to:

  • git checkout master
  • amplify env checkout master
  • git pull origin dev
  • amplify push

From experience, this tends to not work. (If crashing after attempting, use amplify pull to get back to working master) The workflow that has worked is instead:

  • git checkout dev
  • amplify env checkout master
  • amplify push
  • git checkout master
  • git pull origin dev

Updating GraphQL Schema

NOTE: Updating the GraphQL schema through Amplify is a powerful, yet fragile process. As such, experience says that any changes to an existing model in the schema is prone to corrupt the existing data. As such, if such a process is to be done while data that should be preserved exist, precautions must be taken to save the data and recreate it in the new format.

The GraphQL schema can be found in "amplify\backend\api\kompetansekartleggin\build\schema.graphql". Any updates in this file will be added to the backend, and the queries and mutations will be updated to match the new schema.

To update follow these steps:

  • Make the changes wanted to the schema
  • To test the functionality without pushing to the backend, you can run amplify mock api
  • Run amplify push to apply changes to the backend.
  • When prompted to update existing GraphQL resources, choose "Yes".

If making breaking changes, i.e. if creating new indices for a model, following these steps is necessary:

  • Either: Manually delete all data from all the tables in DynamoDB OR
  • Recreate the API (Follow this thread to see if a cleaner method is available yet):
    • Make a copy of the updated schema file anywhere on disk.
    • Make a copy of all files in amplify\backend\api\kompetansekartleggin\resolvers
    • Make a copy all files in amplify\backend\api\kompetansekartleggin\stacks
    • run amplify remove api
    • "Are you sure?": Yes
    • run amplify add api, and choose "GraphQL"
    • "API name": click enter or write desired name.
    • "Authorization type:" Amazon Cognito User Pool
    • "Advanced settings for the GraphQL API?" Yes
    • "Auth types:" No
    • "Conflict detection:" No
    • "Annotated GraphQL schema:" Yes
    • Paste the full (absolute) path to the saved copy.
    • Paste the saved copies of your resolvers and stacks to the original location. Overwrite any conflicting files with the copied versions.
    • run amplify push