Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/amplify-codegen-e2e-core/src/configure/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand Down
62 changes: 56 additions & 6 deletions packages/amplify-codegen-e2e-tests/src/cleanup-e2e-resources.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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',
Expand All @@ -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 = '<Amplify App reused by multiple apps>';
Expand Down Expand Up @@ -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-/;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this regex is wrong. I'm not aware of any functionality of ! on its own. I think this would be matching the ! character literally.

const STALE_DURATION_MS = 2 * 60 * 60 * 1000; // 2 hours in milliseconds

const isCI = (): boolean => process.env.CI && process.env.CODEBUILD ? true : false;
Expand Down Expand Up @@ -175,8 +199,15 @@ const getOrphanTestIamRoles = async (account: AWSAccountInfo): Promise<IamRoleIn
*/
const getAmplifyApps = async (account: AWSAccountInfo, region: string): Promise<AmplifyAppInfo[]> => {
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<string, StackInfo> = {};
try {
Expand Down Expand Up @@ -244,8 +275,28 @@ const getStackDetails = async (stackName: string, account: AWSAccountInfo, regio
};
};

const isRegionEnabled = async (accountInfo: AWSAccountInfo, region: string): Promise<boolean> => {
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<StackInfo[]> => {
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: [
Expand All @@ -264,7 +315,6 @@ const getStacks = async (account: AWSAccountInfo, region: string): Promise<Stack

// We are interested in only the root stacks that are deployed by amplify-cli
const rootStacks = stacks.StackSummaries.filter(stack => !stack.RootId);
const results: StackInfo[] = [];
for (const stack of rootStacks) {
try {
const details = await getStackDetails(stack.StackName, account, region);
Expand Down
Loading