diff --git a/packages/amplify-codegen-e2e-core/src/configure/index.ts b/packages/amplify-codegen-e2e-core/src/configure/index.ts index 347af7b96..a254bba09 100644 --- a/packages/amplify-codegen-e2e-core/src/configure/index.ts +++ b/packages/amplify-codegen-e2e-core/src/configure/index.ts @@ -25,6 +25,13 @@ const defaultProjectSettings = { startCmd: '\r', }; +/** + * This is a list with regions same as Amplify CLI 'configure' dropdown. + * We need to keep order of regions in this list and sync with Amplify CLI regions to prevent + * configuration from failing. + * + * For CI: $CLI_REGION will be selected from this list. + */ export const amplifyRegions = [ 'us-east-1', 'us-east-2', @@ -38,6 +45,7 @@ export const amplifyRegions = [ 'eu-central-1', 'ap-northeast-1', 'ap-northeast-2', + 'ap-northeast-3', 'ap-southeast-1', 'ap-southeast-2', 'ap-south-1', diff --git a/packages/amplify-codegen-e2e-tests/src/cleanup-e2e-resources.ts b/packages/amplify-codegen-e2e-tests/src/cleanup-e2e-resources.ts index 54b9be31a..d8a459812 100644 --- a/packages/amplify-codegen-e2e-tests/src/cleanup-e2e-resources.ts +++ b/packages/amplify-codegen-e2e-tests/src/cleanup-e2e-resources.ts @@ -1,5 +1,5 @@ /* eslint-disable spellcheck/spell-checker, camelcase, @typescript-eslint/no-explicit-any */ -import { CodeBuild } from 'aws-sdk'; +import { CodeBuild, Account } from 'aws-sdk'; import { config } from 'dotenv'; import yargs from 'yargs'; import * as aws from 'aws-sdk'; @@ -8,9 +8,28 @@ import fs from 'fs-extra'; import path from 'path'; import { deleteS3Bucket, sleep } from '@aws-amplify/amplify-codegen-e2e-core'; -// Ensure to update scripts/split-e2e-tests.ts is also updated this gets updated +/** + * Supported regions: + * - All Amplify regions, as reported https://docs.aws.amazon.com/general/latest/gr/amplify.html + * + * NOTE: + * - The list is used to configure correct region in Amplify profile as env var $CLI_REGION + * - 'ap-east-1' is not included in the list due to known discrepancy in Amplify CLI 'configure' command dropdown and supported regions + * + * The list of supported regions must be kept in sync amongst all of: + * - Amplify CLI 'amplify configure' command regions dropdown + * - the internal pipeline that publishes new lambda layer versions + * - amplify-codegen/scripts/e2e-test-regions.json + * - amplify-codegen/scripts/split-canary-tests.ts + * - amplify-codegen/scripts/split-e2e-tests.ts + * - amplify-codegen-e2e-core/src/configure/index.ts + */ +// const REPO_ROOT = path.join(__dirname, '..', '..', '..'); +// const SUPPORTED_REGIONS_PATH = path.join(REPO_ROOT, 'scripts', 'e2e-test-regions.json'); +// const AWS_REGIONS_TO_RUN_TESTS_METADATA: TestRegion[] = JSON.parse(fs.readFileSync(SUPPORTED_REGIONS_PATH, 'utf-8')); +// const AWS_REGIONS_TO_RUN_TESTS = AWS_REGIONS_TO_RUN_TESTS_METADATA.map(region => region.name); + const AWS_REGIONS_TO_RUN_TESTS = [ - 'ap-east-1', 'ap-northeast-1', 'ap-northeast-2', 'ap-northeast-3', @@ -32,6 +51,11 @@ const AWS_REGIONS_TO_RUN_TESTS = [ 'us-west-2', ]; +type TestRegion = { + name: string; + optIn: boolean; +}; + const reportPathDir = path.normalize(path.join(__dirname, '..', 'amplify-e2e-reports')); const MULTI_JOB_APP = ''; @@ -97,7 +121,7 @@ type AWSAccountInfo = { }; const BUCKET_TEST_REGEX = /test/; -const IAM_TEST_REGEX = /!RotateE2eAwsToken-e2eTestContextRole|-integtest$|^amplify-|^eu-|^us-|^ap-/; +const IAM_TEST_REGEX = /!RotateE2eAwsToken-e2eTestContextRole|-integtest|^amplify-|^eu-|^us-|^ap-/; const STALE_DURATION_MS = 2 * 60 * 60 * 1000; // 2 hours in milliseconds const isCI = (): boolean => process.env.CI && process.env.CODEBUILD ? true : false; @@ -175,8 +199,15 @@ const getOrphanTestIamRoles = async (account: AWSAccountInfo): Promise => { const amplifyClient = new aws.Amplify(getAWSConfig(account, region)); - const amplifyApps = await amplifyClient.listApps({ maxResults: 50 }).promise(); // keeping it to 50 as max supported is 50 const result: AmplifyAppInfo[] = []; + + const optStatus = await isRegionEnabled(account, region); + if (!optStatus) { + return result; + } + + const amplifyApps = await amplifyClient.listApps({ maxResults: 50 }).promise(); // keeping it to 50 as max supported is 50 + for (const app of amplifyApps.apps) { const backends: Record = {}; try { @@ -244,8 +275,28 @@ const getStackDetails = async (stackName: string, account: AWSAccountInfo, regio }; }; +const isRegionEnabled = async (accountInfo: AWSAccountInfo, region: string): Promise => { + const account = new Account(getAWSConfig(accountInfo, region)); + const optStatus = await account.getRegionOptStatus({ RegionName: region }).promise(); + + return optStatus.RegionOptStatus === 'ENABLED' || optStatus.RegionOptStatus === 'ENABLED_BY_DEFAULT'; +}; + const getStacks = async (account: AWSAccountInfo, region: string): Promise => { const cfnClient = new aws.CloudFormation(getAWSConfig(account, region)); + const results: StackInfo[] = []; + + const optStatus = await isRegionEnabled(account, region); + if (!optStatus) { + return results; + } + + // console.log('---------'); + // console.log(optStatus); + // console.log(account); + // console.log(region); + // console.log('---------'); + const stacks = await cfnClient .listStacks({ StackStatusFilter: [ @@ -264,7 +315,6 @@ const getStacks = async (account: AWSAccountInfo, region: string): Promise !stack.RootId); - const results: StackInfo[] = []; for (const stack of rootStacks) { try { const details = await getStackDetails(stack.StackName, account, region);