AWS Amplify: Console User Guide

Similar documents
AWS Amplify: Console User Guide

Handel-CodePipeline Documentation

AWS Service Catalog. User Guide

Guides SDL Server Documentation Document current as of 05/24/ :13 PM.

VMware AirWatch Content Gateway for Linux. VMware Workspace ONE UEM 1811 Unified Access Gateway

AWS Serverless Application Repository. Developer Guide

VMware AirWatch Content Gateway for Windows. VMware Workspace ONE UEM 1811 Unified Access Gateway

AWS Tools for Microsoft Visual Studio Team Services: User Guide

Deep Dive on AWS CodeStar

AWS Remote Access VPC Bundle

VMware AirWatch Content Gateway Guide for Linux For Linux

VMware AirWatch Content Gateway Guide for Windows

Talend Component tgoogledrive

Have documentation feedback? Submit a Documentation Feedback support ticket using the Support Wizard on support.air-watch.com.

Amazon WorkSpaces Application Manager. Administration Guide

Testing in AWS. Let s go back to the lambda function(sample-hello) you made before. - AWS Lambda - Select Simple-Hello

Have documentation feedback? Submit a Documentation Feedback support ticket using the Support Wizard on support.air-watch.com.

Product overview. McAfee Web Protection Hybrid Integration Guide. Overview

General. Analytics. MCS Instance Has Predefined Storage Limit. Purge Analytics Data Before Reaching Storage Limit

VMware AirWatch Content Gateway Guide for Windows

USER GUIDE. MADCAP FLARE 2017 r3. Source Control: Git

Table of Contents. Copyright Pivotal Software Inc, of

AWS Elemental MediaStore. User Guide

Red Hat Quay 2.9 Deploy Red Hat Quay - Basic

Guides SDL Server Documentation Document current as of 04/06/ :35 PM.

BLACKBERRY SPARK COMMUNICATIONS PLATFORM. Getting Started Workbook

SOA Software Intermediary for Microsoft : Install Guide

VMware AirWatch Content Gateway Guide for Windows

TIBCO Cloud Integration Security Overview

VMware AirWatch Content Gateway Guide for Windows

Red Hat CloudForms 4.6

GETTING TO KNOW GIT: PART II JUSTIN ELLIOTT PENN STATE UNIVERSITY

Have documentation feedback? Submit a Documentation Feedback support ticket using the Support Wizard on support.air-watch.com.

AWS Elemental MediaLive. User Guide

TM DevOps Use Case TechMinfy All Rights Reserved

Red Hat OpenShift Application Runtimes 1

VMware AirWatch Integration with F5 Guide Enabling secure connections between mobile applications and your backend resources

Amazon WorkMail. User Guide Version 1.0

Oracle Cloud Using the MailChimp Adapter. Release 17.3

Version control system (VCS)

Git Basi, workflow e concetti avanzati (pt2)

Libelium Cloud Hive. Technical Guide

Supported Browsers. General. Clicking Cancel in the Create Instance Dialog Redirects to StackRunner Page. Region Must be Selected for New Stack

VMware AirWatch Content Gateway Guide For Linux

Red Hat JBoss Middleware for OpenShift 3

Deploy Enhancements from Sandboxes

LAB EXERCISE: RedHat OpenShift with Contrail 5.0

DCLI User's Guide. Data Center Command-Line Interface 2.9.1

AWS Quick Start Guide: Back Up Your Files to Amazon Simple Storage Service. Quick Start Version Latest

Using the VMware vrealize Orchestrator Client

Software Development I

Oracle Cloud Using the Google Calendar Adapter. Release 17.3

DCLI User's Guide. Data Center Command-Line Interface

AWS Quick Start Guide. Launch a Linux Virtual Machine Version

Avanan for G Suite. Technical Overview. Copyright 2017 Avanan. All rights reserved.

Topics covered. Introduction to Git Git workflows Git key concepts Hands on session Branching models. Git 2

Continuous integration & continuous delivery. COSC345 Software Engineering

Continuous Integration (CI) with Jenkins

ControlPoint. Native Installation Guide. February 05,

Workspace ONE UEM Notification Service. VMware Workspace ONE UEM 1811

Think Small to Scale Big

Oracle Cloud Using the Microsoft Adapter. Release 17.3

SALESFORCE DMP SUPERTAG USER GUIDE 00. SuperTag User Guide VER. 2, UPDATED 1/16. Rights Reserved, Proprietary &

CLEO VLTrader Made Simple Guide

Oracle Cloud Using the Google Calendar Adapter with Oracle Integration

Swift Web Applications on the AWS Cloud

Linux System Management with Puppet, Gitlab, and R10k. Scott Nolin, SSEC Technical Computing 22 June 2017

Amazon WorkMail. User Guide Version 1.0

Installing and Configuring vcloud Connector

Early Data Analyzer Web User Guide

What is git? Distributed Version Control System (VCS); Created by Linus Torvalds, to help with Linux development;

AWS Elemental MediaPackage. User Guide

How to go serverless with AWS Lambda

BMS Managing Users in Modelpedia V1.1

Coveo Platform 7.0. Yammer Connector Guide

IoT Device Simulator

AWS Lambda + nodejs Hands-On Training

Imperva Incapsula Load Balancer

Installing and Configuring VMware Identity Manager Connector (Windows) OCT 2018 VMware Identity Manager VMware Identity Manager 3.

AgileSCM Release 4.1. AgileSCM Release 4.0. AgileSCM Release 3.2. New Features. Bug Fixes. New Features. Bug Fixes

Git! Fundamentals. IT Pro Roundtable! June 17, 2014!! Justin Elliott! ITS / TLT! Classroom and Lab Computing!! Michael Potter!

DCLI User's Guide. Modified on 20 SEP 2018 Data Center Command-Line Interface

bst Documentation Release John Kelvie, Bela Vizy, Michael Myers

Lab 2 Third Party API Integration, Cloud Deployment & Benchmarking

Installation Guide. McAfee Web Gateway. for Riverbed Services Platform

Amazon Web Services. Block 402, 4 th Floor, Saptagiri Towers, Above Pantaloons, Begumpet Main Road, Hyderabad Telangana India

Ansible Tower Quick Setup Guide

USING GIT FOR AUTOMATION AND COLLABORATION JUSTIN ELLIOTT - MATT HANSEN PENN STATE UNIVERSITY

Vodafone Secure Device Manager Administration User Guide

Sync User Guide. Powered by Axient Anchor

Anchor User Guide. Presented by: Last Revised: August 07, 2017

Oracle Cloud Using the Evernote Adapter. Release 17.3

VMware AirWatch Cloud Connector Guide ACC Installation and Integration

Red Hat OpenShift Application Runtimes 0.1

Workspace ONE UEM Notification Service 2. VMware Workspace ONE UEM 1811

Ionic CLI is the default and easiest way to work with ionic projects. In this tutorial we will learn the ins and outs of Ionic CLI.

McAfee Web Gateway Administration

Event Handler Express Guide

Introduction to Amazon EC2 Container Service (Amazon ECS) Hands On Lab

Eucalyptus User Console Guide

Transcription:

AWS Amplify Console User Guide AWS Amplify: Console User Guide Copyright 2018 Amazon Web Services, Inc. and/or its affiliates. All rights reserved.

Amazon's trademarks and trade dress may not be used in connection with any product or service that is not Amazon's, in any manner that is likely to cause confusion among customers, or in any manner that disparages or discredits Amazon. All other trademarks not owned by Amazon are the property of their respective owners, who may or may not be affiliated with, connected to, or sponsored by Amazon.

Table of Contents What is the AWS Amplify Console?... 1 What are Modern Web Applications?... 1 Amplify Console Features... 1 Next Step... 2 Getting Started... 3 Step 1: Connect Repository... 3 Step 2: Confirm Build Settings for the Front End... 4 Step 3: Confirm Build Settings for the Backend (beta)... 5 Step 4: Add Environment Variables (Optional)... 5 Step 5: Save and Deploy... 6 Next Steps... 6 Setting Up Custom Domains... 7 Adding a Custom Domain Managed in Amazon Route 53... 7 Adding a Custom Domain Managed by a Third-Party DNS Provider... 8 Managing Subdomains... 10 Associating a Domain... 10 Deploying Serverless Backends... 11 Managing Multiple Environments... 12 Using Branch-based Environmments... 12 Using Team Workflows... 12 Using a Centralized Workflow... 13 Using a Feature Branch Workflow... 14 Using the GitFlow Workflow... 15 Using Redirects... 16 Types of Redirects... 16 Parts of a Redirect... 17 Order of Redirects... 17 Simple Redirects and Rewrites... 18 Reverse Proxy Rewrite... 19 Placeholders... 19 Query Strings and Path Parameters... 19 Redirects for Single Page Web Apps (SPA)... 20 Region-based Redirects... 20 Restricting Access... 21 Configuring Build Settings... 22 YML Specification Syntax... 22 Build Scenarios... 23 Using Branch-Specific Build Settings... 23 Navigating to a Subfolder... 23 Deploying the Backend with Your Front End... 24 Setting the Output Folder... 24 Installing Packages as Part of Your Build... 24 Using a Private npm Registry... 24 Installing OS packages... 25 Setting Environment Variables... 26 Connecting to Third-Party Custom Domains... 27 Connecting to a GoDaddy Domain... 27 Connecting to a Google Domain... 28 Creating a Service Role... 30 Step 1: Create a Service Role... 30 Step 2: Accept All Defaults in the AWS CloudFormation Console... 30 Step 3: Return to the Amplify Console... 30 Managing Your App's Performance... 31 iii

What are Modern Web Applications? What is the AWS Amplify Console? The AWS Amplify Console is a continuous delivery and hosting service for modern web applications. The AWS Amplify Console simplifies the deployment of your application front end and backend. Connect to your code repository and your front end and backend are deployed in a single workflow, on every code commit. This ensures that your web application is only updated after the deployment is successfully completed, eliminating inconsistencies between your application front end and backend. AWS Amplify Console makes it easier for you to build, deploy, and host your mobile web applications, enabling you to quickly iterate on feedback and get new features to your users faster. What are Modern Web Applications? Modern web applications are constructed as single page web applications that package all application components into static files. Traditional client-server web architectures led to poor experiences-- every button click or search required a round trip to the server, re-rendering the entire application. Modern web apps offer a native app-like user experience by serving the app front end, or user interface, efficiently to browsers as prebuilt HTML/JavaScript files that can then invoke backend functionality without reloading the page. Modern web applications functionality is often spread across multiple places--such as databases, authentication services, front end code running in the browser, and backend business logic, or AWS Lambda functions, running in the cloud. This makes application deployments complex and timeconsuming as developers need to carefully coordinate deployments across the front end and backend to avoid partial or failed deployments. The AWS Amplify Console simplifies deployment of the front end and backend in a single workflow. AWS Amplify Console supports common Single Page App (SPA) frameworks (e.g. React, Angular, Vue.js, Ionic, Ember), as well as static-site generators like Gatsby, Eleventy, Hugo, VuePress, and Jekyll. Amplify Console Features With the Amplify Console, you can do the following: Connect your repository (GitHub, BitBucket, GitLab, and AWS CodeCommit), and the Amplify Console automatically detects the front end build settings along with any backend functionality provisioned with the Amplify CLI (command-line toolchain for creating serverless backends). Manage production and staging environments for your front end and backend by connecting new branches. Atomic deployments eliminate maintenance windows by ensuring that the web app is only updated when the entire deployment has finished. This eliminates scenarios where files fail to upload properly. Connect your custom domain. If you manage your domain in Amazon Route 53, the Amplify Console automatically connects the root (yourdomain.com), www subdomains (www.yourdomain.com), and branch (https://dev.yourdomain.com) subdomains. Get screen shots of your app rendered on different mobile devices to pinpoint layout issues. Set up rewrites and redirects to maintain SEO rankings. Password protect your web app so you can work on new features without making them publicly accessible. 1

Next Step Next Step Get started (p. 3) with the Amplify Console. 2

Step 1: Connect Repository Getting Started In this walkthrough, you learn how to continuously build, deploy, and host a modern web app. Modern web apps include Single Page App (SPA) frameworks (for example, React, Angular, or Vue) and static-site generators (SSGs) (for example, Hugo, Jekyll, or Gatsby). To get started, log in to the Amplify Console and choose Get Started under Deploy. Step 1: Connect Repository Connect your GitHub, Bitbucket, GitLab, or AWS CodeCommit repositories. After you authorize the Amplify Console, Amplify fetches an access token from the repository provider, but it doesn't store the token on the AWS servers. Amplify accesses your repository using deploy keys installed in a specific repository only. After you connect the repository service provider, choose a repository, and then choose a corresponding branch to build and deploy. 3

Step 2: Confirm Build Settings for the Front End Step 2: Confirm Build Settings for the Front End For the selected branch, Amplify inspects your repository to automatically detect the sequence of build commands to be executed. Important: Verify that the build commands and build output directory (that is, artifactsbasedirectory) is accurate. If you need to modify this information, choose Edit to open the YML editor. You can save your build settings on our servers, or you can download the YML and add it to the root of your repo (for monorepos, store the YML at the app's root directory). 4

Step 3: Confirm Build Settings for the Backend (beta) For more information, see YML structure (p. 22). Step 3: Confirm Build Settings for the Backend (beta) The Amplify Console detects apps that are using the Amplify Framework and can deploy backend resources in a single workflow with the front end build. This enables you to manage production and test environments with your Git workflow. To deploy backend functionality using the Amplify CLI during your build, create or reuse an IAM service role. IAM roles are a secure way to grant the Amplify Console permissions to act on resources in your account. Note: The Amplify CLI won't run without an IAM service role enabled. For more information, see Deploy a serverless backend with the Amplify Console. (p. 11). Step 4: Add Environment Variables (Optional) Almost every app needs to get configuration information at runtime. These configurations can be database connection details, API keys, or different parameters. Environment variables provide a means to expose these configurations at build time. 5

Step 5: Save and Deploy Step 5: Save and Deploy Review all of your settings to ensure everything is set up correctly. Choose Save and deploy to deploy your web app to a global content delivery network (CDN). Your front end build typically takes 1 to 2 minutes but can vary based on size of the app. Access the build logs screen by selecting a progress indicator on the branch tile. A build has the following stages: 1. Provision - Your build environment is set up using a Docker image on a host with 4 vcpu, 7GB memory. Each build gets its own host instance, ensuring that all resources are securely isolated. The contents of the Docker file are displayed to ensure that the default image supports your requirements. 2. Build - The build phase consists of three stages: setup (clones repository into container), deploy backend (runs the Amplify CLI to deploy backend resources), and build front end (builds your frontend artifacts). 3. Deploy - When the build is complete, all artifacts are deployed to a hosting environment managed by Amplify. Every deployment is atomic - atomic deployments eliminate maintenance windows by ensuring that the web app is only updated after the entire deployment has completed. 4. Verify - To verify that your app works correctly, Amplify renders screen shots of the index.html in multiple device resolutions using Headless Chrome. Next Steps Add a custom domain to your app (p. 7) Manage multiple environments (p. 12) 6

Adding a Custom Domain Managed in Amazon Route 53 Setting Up Custom Domains You can connect a custom domain purchased through domain registrars (for example, Amazon Route 53, GoDaddy, and Google Domains) to your app. When you deploy your web app with the Amplify Console, it is hosted at: https://branch-name.d1m7bkiki6tdw1.amplifyapp.com When you use a custom domain, users see that your app is hosted from a URL, like the following: https://www.awesomedomain.com The Amplify Console issues an SSL certificate for all domains connected to your app so that all traffic is secured through HTTPS/2. The SSL certificate generated by Amazon Certificate Manager is valid for 30 days and renews automatically as long as your app is hosted with Amplify. Topics Adding a Custom Domain Managed in Amazon Route 53 (p. 7) Adding a Custom Domain Managed by a Third-Party DNS Provider (p. 8) Managing Subdomains (p. 10) Associating a Domain (p. 10) Adding a Custom Domain Managed in Amazon Route 53 After you deploy your app, you can add a custom domain that you manage using Amazon Route 53. 1. On the left navigation pane, choose App Settings, Domain management, and then choose Add domain. 2. In Enter your root domain, enter your root domain (https://awesomedomain.com). As you start typing, root domains that you manage in Amazon Route 53 appear in the list (https:// awesomedomain.com). 3. Select the domain you want to use and then choose Find Domain and Save. 7

Adding a Custom Domain Managed by a Third-Party DNS Provider The Amplify Console automatically updates the DNS records for your root (https://awesomedomain.com) and www subdomain (https://www.awesomedomain.com) in Amazon Route 53. We also set up a redirect for https://www.awesomedomain.com to point to https://awesomedomain.com (you can change this by choosing Rewrites and redirects from the left menu). Note It typically takes 10 to 30 minutes for DNS to propagate and issue the SSL certificate, but it can take up to 24 hours. For more information about the status messages, see Associating a Domain (p. 10). Adding a Custom Domain Managed by a Third- Party DNS Provider After you deploy your app, you can add a custom domain that you manage using a third-party DNS provider if you don't use Amazon Route 53. 1. On the left navigation pane, choose App Settings, Domain management, and then choose Add domain. 2. In Enter your root domain, enter your root domain (https://awesomedomain.com) and then choose Find domain. If the domain is registered, a green alert notifies you to proceed as long you are the owner of the domain. If the domain is available, purchase a domain at Amazon Route 53. 3. Choose Save. The Amplify Console adds two entries for https://www.awesomedomain.com and https://awesomedomain.com with a redirect set up from the www subdomain to the root domain. 8

Adding a Custom Domain Managed by a Third-Party DNS Provider Because the domain is managed externally you must manual configure your DNS provider (for example, GoDaddy or Google domains). 4. To assign a domain to your app deployment, choose View DNS records in the alert banner. 5. Update your DNS providers' CNAME and ALIAS records as follows. For GoDaddy and Google Domains, see the step-by-step instructions in Connecting to Third-Party Custom Domains (p. 27). a. Configure CNAME record to point all subdomains (https://*.awesomedomain.com) to the amplifyapp domain. b. Configure ANAME/ALIAS record to point the root domain (https://awesomedomain.com) to your amplifyapp domain. ANAME records enable you to point the root of your domain to a hostname. For DNS providers that do not have ANAME/ALIAS support, we strongly recommend migrating your DNS to Amazon Route 53. c. To generate a SSL certificate for your domain, Amazon Certificate Manager (ACM) needs to verify ownership. Configure a CNAME to point to ACM's validation server. Once ACM validates ownership of your domain, all traffic will be served using HTTPS/2. Important: Verification of domain ownership and DNS propagation for third-party domains can take up to 48 hours. For more information about status messages, see Associating a Domain (p. 10). 9

Managing Subdomains Managing Subdomains A subdomain is the part of your URL that appears before your domain name (for example, www.amazon.com or aws.amazon.com). For domains managed using Route 53, the Amplify Console automatically creates subdomains for all connected branches. For example, when you connect a dev branch, the Amplify Console creates a deployment at https://dev.<app-id>.amplifyapp.com without requiring any extra configuration. If you want the same functionality for third-party providers you must configure the DNS. If you want the same functionality for third-party providers, configure the DNS to give Amplify Console wildcard (*) access to all subdomains. Associating a Domain When you are associating a domain with your Amplify app deployment, you see the following status messages: 1. In Progress - First attempt at updating your DNS record. This indicates that Amplify is able to update records managed in Route 53, but unable to do so for third-party DNS providers. 2. Pending verification - Before issuing an SSL certificate, Amazon Certificate Manager (ACM) must verify that you are the owner of the domain. Domains managed outside Amazon Route 53 usually take the longest time to verify. 3. Pending deployment - After domain verification, the DNS is propagated globally to all 144 points of presence of our CDN. 4. Available - The domain is successfully associated with your app. 10

Deploying Serverless Backends with Your Front End (Beta) Note: This feature is currently only available to users of the beta version of the Amplify CLI, which supports multiple environments. Get started with the feature by installing the Amplify CLI. npm install -g @aws-amplify/cli@multienv. The Amplify Console enables developers building apps with the Amplify Framework to continuously deploy updates to their backend and front end on every code commit. With the Amplify Console you can deploy serverless backends with GraphQL APIs, authentication, analytics, and storage created by the Amplify CLI. 1. Connect any repository and branch that was initialized by the Amplify CLI (Note: Install the beta version of the CLI: npm install -g @aws-amplify/cli@multienv). 2. The Amplify Console automatically detects backends provisioned with the Amplify CLI and adds a backend stage to the build YML that looks like this: version: 1.0 env: variables: key: value backend: phases: build: - export STACKINFO="$(envCache --get stackinfo)" - amplifypush --environment $AWS_BRANCH - envcache --set stackinfo "$(amplify env get --json --name $AWS_BRANCH)" amplifypush - The amplifypush script is a helper script that enables users to specify an environment name as an input and runs the Amplify CLI to create or update an environment. On first build, we create a backend environment that corresponds to the name of the connected branch. ($AWS_BRANCH is a system-defined environment variable). If you want to reuse an existing Amplify environment, modify the $AWS_BRANCH to point to the env-name. Example usage: amplifypush --environment ENV_NAME envcache - The envcache provides key-value storage at build time. The envcache can only be modified during a build and can be re-used at the next build. Using the envcache, we can store information on the deployed environment and make it available to the build container in successive builds. Environment variables in comparison, cannot be modified during a build. Example usage: envcache --set <key> <value> envcache --get <key> <value> 3. Choose Next and Save and deploy. Your app build will start by deploying the backend followed by the front end. 11

Using Branch-based Environmments Managing Multiple Environments and Team Workflows Using Branch-based Environmments The Amplify Console leverages Git branches to create new environments every time a developer connects a new branch in their repository. After connecting your first branch, you can create a new environment by adding a branch as follows: 1. On the branch list page, choose Connect branch. 2. Choose a branch from your repository. 3. Accept the autodetected build settings or modify them according to your app requirements. 4. Save and then deploy your app. Your app now has two front end environments available at https://master.appid.amplifyapp.com and https://dev.appid.amplifyapp.com. If your app has a backend provisioned with the Amplify CLI (beta), the Amplify Console deploys separate backends per branch. Connecting a branch creates front end and backend environments, which enables developers to work in sandbox environments and use Git as a mechanism to merge code and resolve conflicts. Using Team Workflows For teams that are building serverless apps with the Amplify CLI, we recommend the following: 12

Using a Centralized Workflow That each developer in a team creates a sandbox environment in the cloud that is separate from their local computer. This allows developers to work in isolation from each other without overwriting other team members' changes. That your team connects production, test, and feature branches to the Amplify Console. This ensures that the Amplify Console uses the Git repository as a single source of truth from which to deploy changes, rather than relying on developers on the team to manually push their backend or front end to production from their local computers. The Amplify Console is designed to work with all team workflows such as centralized, feature branch, and GitFlow workflows. Using a Centralized Workflow Teams that transition from SVN to Git practice this workflow. With this workflow, every developer on the team commits code directly to the default branch called master. Each developer clones a local copy of the repository, works independently and then pushes code to merge it to the master branch. For example: 1. Connect master to the Amplify Console for continuous deployment. 2. Both Kita and Cody check out the master branch locally and then run the amplify init command to set up a cloud backend to make changes to the front end and backend from their local computers. 3. After the code has been tested locally, Kita pushes the code to the master branch. This kicks off a build in the Amplify Console that updates any front end or backend content that has changed. The following command line example and diagram capture the workflow. > git fetch && git checkout master > amplify init? Do you want to use an existing environment? false? Enter a name for the environment kita-sandbox // Provide AWS Profile info // Test feature locally > npm run start > git commit -m "New feature" && git push origin master 13

Using a Feature Branch Workflow Using a Feature Branch Workflow The main idea behind the feature branch workflow is that feature work happens in a separate branch from the master branch. This enables developers to work on new features in isolation from what is production. When the feature is ready it's merged into the master branch. Similar to the steps in the centralized workflow, all team members work on the feature branch pushing updates to that branch until it's ready to be merged to the master branch. The feature branch is also connected to the Amplify Console (password protected) for continuous deployment so developers can share updates with other stakeholders. 14

Using the GitFlow Workflow Using the GitFlow Workflow GitFlow uses two branches to record the history of the project. The master branch tracks release code only, and the develop branch is used as an integration branch for new features. GitFlow simplifies parallel development by isolating new development from completed work. New development (such as features and non-emergency bug fixes) is done in feature branches. When the developer is satisfied that the code is ready for release, the feature branch is merged back into the integration develop branch. The only commits to the master branch are merges from release branches and hotfix branches (to fix emergency bugs). The diagram below shows which branches are typically connected to the Amplify Console in this model. 15

Types of Redirects Using Redirects Redirects enable a web server to reroute navigation from one URL to another. Common reasons for using redirects include: to customize the appearance of URL, to avoid broken links, to move the hosting location of an app or site without changing its address, and to change a requested URL to the form needed by a web app. Types of Redirects There are several types of redirects that support specific scenarios. Permanent redirect (301) 301 redirects are intended for lasting changes to the destination of a web address. Search engine ranking history of the original address applies to the new destination address. Redirection occurs on the clientside, so a browser navigation bar shows the destination address after redirection. Common reasons to use 301 redirects include: To avoid a broken link when the address of a page changes. To avoid a broken link when a user makes a predictable typo in an address. Temporary redirect (302) 302 redirects are intended for temporary changes to the destination of a web address. Search engine ranking history of the original address doesn't apply to the new destination address. Redirection occurs on the client-side, so a browser navigation bar shows the destination address after redirection. Common reasons to use 302 redirects include: To provide a detour destination while repairs are made to an original address. To provide test pages for A/B comparison of user interface. Rewrite (200) 200 redirects (rewrites) are intended to show content from the destination address as if it were served from the original address. Search engine ranking history continues to apply to the original address. Redirection occurs on the server-side, so a browser navigation bar shows the original address after redirection. Common reasons to use 200 redirects include: To redirect an entire site to a new hosting location without changing the address of the site. To redirect all traffic to a single page web app (SPA) to its index.html page for handling by a client-side router function. Not Found (404) 404 redirects occur when a request points to an address that doesn't exist. The destination page of a 404 is displayed instead of the requested one. Common reasons a 404 redirect occurs include: To avoid a broken link message when a user enters a bad URL. To point requests to nonexistent pages of a web app to its index.html page for handling by a clientside router function. 16

Parts of a Redirect Parts of a Redirect Redirects consist of the following: An original address - The address the user requested. A destination address - The address that actually serves the content that the user sees. A redirect type - Types include a permanent redirect (301), a temporary redirect (302), a rewrite (200), or not found (404). A two letter country code (optional) - a value you can include to segment the user experience of your app by region To create and edit redirects, choose Rewrites and redirects settings in the left navigation pane. To bulk edit redirects in a JSON editor, choose Open text editor. Order of Redirects Redirects are executed from the top of the list down. Make sure that your ordering has the effect you intend. For example, the following order of redirects causes all requests for a given path under /docs/ to redirect to the same path under /documents/, except /docs/specific-filename.html which redirects to / documents/different-filename.html: /docs/specific-filename.html /documents/diferent-filename.html 301 /docs/<*> /documents/<*> The following order of redirects ignores the redirection of specific-filename.html to differentfilename.html: /docs/<*> /documents/<*> /docs/specific-filename.html /documents/diferent-filename.html 301 17

Simple Redirects and Rewrites Simple Redirects and Rewrites In this section we include example code for common redirect scenarios. You can use the following example code to permanently redirect a specific page to a new address. Original address Destination Address Redirect Type Country Code /original.html /destination.html permanent redirect (301) JSON: [{"source": "/original.html", "status": "301", "target": "/destination.html", "condition": null}] You can use the following example code to redirect any path under a folder to the same path under a different folder. Original address Destination Address Redirect Type Country Code docs/<*> /documents/<*> permanent redirect (301) JSON [{"source": "/docs/<*>", "status": "301", "target": "/documents/<*>", "condition": null}] You can use the following example code to redirect all traffic to index.html as a rewrite. In this scenario, the rewrite makes it appear to the user that they have arrived at the original address. Original address Destination Address Redirect Type Country Code <*> index.html rewrite (200) JSON [{"source": "/<*>", "status": "200", "target": "/index.html", "condition": null}] You can use the following example code to use a rewrite to change the subdomain that appears to the user. Original address Destination Address Redirect Type Country Code https:// mydomain.com https:// www.mydomain.com rewrite (200) JSON [{"source": "/<*>", "status": "200", "target": "/index.html", "condition": null}] You can use the following example code to redirect paths under a folder that can't be found to a custom 404 page. Original address Destination Address Redirect Type Country Code /<*> /404.html not found (404) 18

Reverse Proxy Rewrite JSON [{"source": "/<*>", "status": "404", "target": "/404.html", "condition": null}] Reverse Proxy Rewrite The following example uses a rewrite to proxy content from another location so that it appears to user that the domain hasn't changed: Original address Destination Address Redirect Type Country Code /images https:// rewrite (200) images.otherdomain.com JSON [{"source": "/<*>", "status": "200", "target": "/index.html", "condition": null}] Placeholders You can use the following example code to redirect paths in a folder structure to a matching structure in another folder. Original address Destination Address Redirect Type Country Code /docs/<year>/ <month>/<date>/ <itemid> /documents/<year>/ <month>/<date>/ <itemid> permanent redirect (301) JSON [{"source": "/docs/<year>/<month>/<date>/<itemid>", "status": "301", "target": "/documents/<year>/<month>/<date>/<itemid>", "condition": null}] Query Strings and Path Parameters You can use the following example code to redirect a path to a folder with a name that matches the value of a query string element in the original address: Original address Destination Address Redirect Type Country Code /docs?id=<my-blogid-value /documents/<myblog-post-idvalue> permanent redirect (301) JSON [{"source": "/docs?id=<my-blog-id-value", "status": "301", "target": "/documents/<my-blog-post-id-value>", "condition": null}] You can use the following example code to redirect all paths that can't be found at a given level of a folder structure to index.html in a specified folder. Original address Destination Address Redirect Type Country Code 19

Redirects for Single Page Web Apps (SPA) /documents/ <folder>/<childfolder>/<grandchild-folder> /documents/ index.html 404 JSON [{"source": "/documents/<x>/<y>/<z>", "status": "404", "target": "/documents/index.html", "condition": null}] Redirects for Single Page Web Apps (SPA) Most SPA frameworks support HTML5 history.pushstate() to change browser location without triggering a server request. This works for users who begin their journey from the root (or /index.html), but fails for users who navigate directly to any other page. To solve this we set up a 200 rewrite to allow the SPA router to handle the routing of the URL. Original address Destination Address Redirect Type Country Code /<*> index.html 200 JSON [{"source": "<*>", "status": "200", "target": "/documents/index.html", "condition": null}] Region-based Redirects You can use the following example code to redirect requests based on region. Original address Destination Address Redirect Type Country Code /documents /documents/us/ 302 JSON [{"source": "/documents", "status": "302", "target": "/documents/us/", "condition": "<US>"}] 20

Restricting access Password protect feature branches that are not ready to be accessed publicly. 1. Choose App settings and then choose Access control. 2. In the list of your connected branches, choose Manage access in the top-right corner. 3. Do one of the following: You can set a global password that you want to apply to all connected branches. For example, if you have master, dev, and feature connected, you can use a global password to set the same user name and password for all branches. You can set a password at the branch level. 21

YML Specification Syntax Configuring Build Settings The Amplify Console automatically detects the front end framework and associated build settings by inspecting the package.json file in your repository. You have the following options: Save the build settings in the Amplify Console - The Amplify Console autodetects build settings and saves it so that they can be accessed via the Amplify Console. These settings are applied to all of your branches unless there is a YML file found in your repository. Save the build settings in your repository - Download the amplify.yml file and add it to the root of your repository (or root of the app folder for monorepos). You can edit these settings in the Amplify Console by choosing App Settings>Build settings. These build settings are applied to all the branches in your app, except for the branches that have a YML file saved in the repository. YML Specification Syntax The build specification YML contains a collection of build commands and related settings that the Amplify Console uses to run your build. The YML is structured as follows: version: 1.0 env: variables: key: value backend: phases: prebuild: commands: - *enter command* build: commands: - *enter command* postbuild: commands: - *enter command* frontend: phases: prebuild: commands: - cd react-app - npm ci build: commands: - npm run build artifacts: files: - location - location discard-paths: yes basedirectory: location cache: paths: - path 22

Build Scenarios - path version - Represents the Amplify Console YML version number. env - Add environment variables to this section. You can also add environment variables using the console. backend - Run Amplify CLI commands to provision a backend, update Lambda functions, or GraphQL schemas as part of continuous deployment. Learn how to deploy a backend with your frontend (p. 11). frontend - Run frontend build commands. Both the frontend and backend have three phases that represent the commands run during each sequence of the build. prebuild - The prebuild script runs before the actual build starts, but after we have installed dependencies. build - Your build commands. postbuild - The post-build script runs after the build has finished and we have copied all the necessary artifacts to the output directory. artifacts>base-directory - The directory in which your build artifacts exist. artifacts>files - Specify files from your artifact you want to deploy. **/* is to include all files. Build Scenarios The following scenarios describe how to write your build YML. Using Branch-Specific Build Settings To set branch-specific build settings, add the buildspec YML to the root of your repository. You can do this any of the following ways: When connecting a new branch, choose Edit. Make your edits and then choose Save and add to my repo. The Amplify Console automatically adds the YML to your repository when you deploy the branch. Note: If you do not want these settings to apply to all branches, make sure you don't merge this file into the other branches. In the Amplify Console, choose App settings, choose Build settings, and then choose Download. Make your edits and then add this file to the root of your repository. Navigating to a Subfolder For monorepos, users want to be able to cd into a folder to run the build. After you run the cd command, it applies to all stages of your build so you don't need to repeat the command in separate phases. version: 1.0 env: variables: key: value frontend: phases: prebuild: commands: - cd react-app - npm ci build: commands: 23

Deploying the Backend with Your Front End - npm run build Deploying the Backend with Your Front End Use the Amplify CLI to deploy a backend with your front end. Learn more (p. 11) about how envcache and amplifypush commands help you with backend deployments. The $AWS_BRANCH is a system defined environment variable that picks up the current branch. The build settings below will deploy a new backend environment linked to each feature branch. version: 1.0 env: variables: key: value backend: phases: build: commands: - export STACKINFO="$(envCache --get stackinfo)" - amplifypush --environment $AWS_BRANCH - envcache --set stackinfo "$(amplify env get --json --name $AWS_BRANCH)" Setting the Output Folder The following build settings set the output directory to the public folder. frontend: phases: commands: build: - yarn run build artifacts: basedirectory: public Installing Packages as Part of Your Build You can use npm or yarn to install packages during the build. frontend: phases: build: commands: - npm install -g pkg-foo - pkg-foo deploy - yarn run build artifacts: basedirectory: public Using a Private npm Registry You can add references to a private registry in your build settings or add it as an environment variable. build: phases: prebuild: commands: - npm config set <key> <value> 24

Installing OS packages - npm config set registry https://registry.npmjs.org - npm config set always-auth true - npm config set email hello@amplifyapp.com - yarn install Installing OS packages You can install OS packages for missing dependencies. build: phases: prebuild: commands: - yum install -y <package> 25

Setting Environment Variables Environment variables are key-value pairs that are available at build time. These configurations can be anything, including: Database connection details Third-party API keys Different customization parameters Secrets As a best practice, you can use environment variables to expose these configurations. All environment variables that you add are encrypted to prevent rogue access so you can use them to store secret information. 1. In the Amplify console, choose App Settings and then choose Environment Variables. 2. In the key and value fields, enter all your app environment variables. By default, the Amplify console applies the environment variables across all branches, so you don't have to re-enter variables when you connect a new branch. 3. Choose Save. If you need to customize a variable specifically for a branch, you can add a branch override. To do this, choose Actions and then choose Add variable override. You now have a set of environment variables specific to your branch. 26

Connecting to a GoDaddy Domain Connecting to Third-Party Custom Domains Connecting to a GoDaddy Domain 1. Follow the instructions to add a domain (p. 7) for third-party providers. 2. Log in to your account at GoDaddy and choose DNS. 3. Add CNAME records to to point all subdomains to the amplifyapp domain, and another CNAME record to point to Amazon Certificate Manager's validation server. A single validated ACM generates an SSL certificate for your domain. Make sure you only enter the subdomain (for example, ) in **Host* as shown below (don't enter yourdomainname.com). GoDaddy doesn't support ANAME/ALIAS records. For DNS providers that don't have ANAME/ALIAS support, we strongly recommend migrating your DNS to Amazon Route 53. If you want to keep your 27

Connecting to a Google Domain current provider and update the root domain, add Forwarding and set up a domain forward. In Forward to, enter the information as shown following: Connecting to a Google Domain 1. Follow the instructions to add a domain (p. 7) for third-party providers. 2. Log in to your account at https://domains.google and choose DNS. 3. In Custom resource records, enter CNAME records that you want to point all subdomains (https:// *.awesomedomain.com) to the amplifyapp domain, and another CNAME record to point to Amazon Certificate Manager's validation server. A single validated ACM generates an SSL certificate for your domain. 28

Connecting to a Google Domain Google domains don't support ANAME/ALIAS records. For DNS providers that don't have ANAME/ ALIAS support, we strongly recommend migrating your DNS to Amazon Route 53. If you want to keep your current provider and update the root domain, add a Synthetic Record, and set up a Subdomain Forward. In Subdomain, enter the @ symbol and then choose Forward path as shown following: 29

Step 1: Create a Service Role Adding a Service Role to the Amplify Console When You Connect an App The Amplify Console requires permissions to deploy backend resources with your front end. You use a service role to accomplish this. A service role is the IAM role that Amplify Console assumes when calling other services on your behalf. Step 1: Create a Service Role Right-click the following link and choose Open link in new tab. It opens the CloudFormation console with pre-selected defaults. Step 2: Accept All Defaults in the AWS CloudFormation Console In the CloudFormation console, accept all defaults on the four screens to create a role. This role allows the Amplify Console to deploy backend resources during a build. Step 3: Return to the Amplify Console In the Amplify Console onboarding screen, choose refresh, and then pick the role you just created. It should look like AmplifyConsoleServiceRole-AmplifyRole-XXXXXXXXXXX. The Amplify Console now has permissions to deploy backend resources. 30

Managing Your App's Performance You can control how long your objects stay in a CDN cache before the CDN forwards another request to your origin. Reducing the duration enables you to serve dynamic content. Increasing the duration means your users get better performance because your objects are more likely to be served directly from the edge cache. A longer duration also reduces the load on your origin. You can set the default TTL for your web app in the console: 1. In the console, choose App settings and then choose General. 2. From the list of branches, choose a branch, choose Action, and then choose Adjust TTL. The longer you set the TTL, the better your performance. The shorter you set the TTL, the faster you can deploy. During development, we recommend setting a default TTL of 5 seconds for your branch. After your app is in production, you can increase the TTL based on your preference. We recommend that you set it to anything about 60 seconds for production traffic. 31