From 13abcf47051a2a7a2bf7f94af7b268ed1365adbd Mon Sep 17 00:00:00 2001 From: John Corser Date: Thu, 9 Sep 2021 18:43:43 -0400 Subject: [PATCH] chore(amplify-provider-awscloudformation): add env vars for configuring development against beta/gamma (#8121) --- packages/amplify-cli/src/pre-deployment-pull.ts | 5 +++-- .../amplify-provider-awscloudformation/src/admin-login.ts | 3 ++- .../src/utils/admin-helpers.ts | 6 ++++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/amplify-cli/src/pre-deployment-pull.ts b/packages/amplify-cli/src/pre-deployment-pull.ts index f9c67e2bdfa..31778cd87f1 100644 --- a/packages/amplify-cli/src/pre-deployment-pull.ts +++ b/packages/amplify-cli/src/pre-deployment-pull.ts @@ -7,8 +7,9 @@ import * as path from 'path'; export async function preDeployPullBackend(context: $TSContext, sandboxId: string) { const providerPlugin = await import(context.amplify.getProviderPlugins(context).awscloudformation); - - const url = `${providerPlugin.adminBackendMap['us-east-1'].appStateUrl}/AppState/${sandboxId}`; + // environment variable AMPLIFY_CLI_APPSTATE_BASE_URL useful for development against beta/gamma appstate endpoints + const appStateBaseUrl = process.env.AMPLIFY_CLI_APPSTATE_BASE_URL ?? providerPlugin.adminBackendMap['us-east-1'].appStateUrl; + const url = `${appStateBaseUrl}/AppState/${sandboxId}`; // Fetch schema const res = await fetch(`${url}`); diff --git a/packages/amplify-provider-awscloudformation/src/admin-login.ts b/packages/amplify-provider-awscloudformation/src/admin-login.ts index 58c53e11d08..5904b29cb6b 100644 --- a/packages/amplify-provider-awscloudformation/src/admin-login.ts +++ b/packages/amplify-provider-awscloudformation/src/admin-login.ts @@ -23,7 +23,8 @@ export async function adminLoginFlow(context: $TSContext, appId: string, envName const spinner = ora('Continue in browser to log in…\n').start(); try { // spawn express server locally to get credentials - const originUrl = adminBackendMap[region].amplifyAdminUrl; + // environment variable AMPLIFY_CLI_ADMINUI_BASE_URL is used to set the login url to http://localhost:3000 when developing against beta/gamma endpoints + const originUrl = process.env.AMPLIFY_CLI_ADMINUI_BASE_URL ?? adminBackendMap[region]?.amplifyAdminUrl; const adminLoginServer = new AdminLoginServer(appId, originUrl, context.print); await new Promise(resolve => adminLoginServer.startServer(() => { diff --git a/packages/amplify-provider-awscloudformation/src/utils/admin-helpers.ts b/packages/amplify-provider-awscloudformation/src/utils/admin-helpers.ts index 1bbc2a42859..41417a65056 100644 --- a/packages/amplify-provider-awscloudformation/src/utils/admin-helpers.ts +++ b/packages/amplify-provider-awscloudformation/src/utils/admin-helpers.ts @@ -6,7 +6,7 @@ import { adminLoginFlow } from '../admin-login'; import { AdminAuthConfig, AwsSdkConfig, CognitoAccessToken, CognitoIdToken } from './auth-types'; export const adminVerifyUrl = (appId: string, envName: string, region: string): string => { - const baseUrl = adminBackendMap[region].amplifyAdminUrl; + const baseUrl = process.env.AMPLIFY_CLI_ADMINUI_BASE_URL ?? adminBackendMap[region]?.amplifyAdminUrl; return `${baseUrl}/admin/${appId}/${envName}/verify/`; }; @@ -45,7 +45,9 @@ export async function getTempCredsWithAdminTokens(context: $TSContext, appId: st } async function getAdminAppState(appId: string, region: string) { - const res = await fetch(`${adminBackendMap[region].appStateUrl}/AppState/?appId=${appId}`); + // environment variable AMPLIFY_CLI_APPSTATE_BASE_URL useful for development against beta/gamma appstate endpoints + const appStateBaseUrl = process.env.AMPLIFY_CLI_APPSTATE_BASE_URL ?? adminBackendMap[region].appStateUrl; + const res = await fetch(`${appStateBaseUrl}/AppState/?appId=${appId}`); return res.json(); }