Skip to content

Commit 4e05757

Browse files
committed
chore: revert changes
Signed-off-by: Kevin Shan <[email protected]>
1 parent 914a65b commit 4e05757

File tree

1 file changed

+27
-34
lines changed

1 file changed

+27
-34
lines changed

packages/amplify-codegen-e2e-tests/src/cleanup-e2e-resources.ts

Lines changed: 27 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable spellcheck/spell-checker, camelcase, @typescript-eslint/no-explicit-any */
2-
import { CodeBuild, Account } from 'aws-sdk';
2+
import { CodeBuild } from 'aws-sdk';
33
import { config } from 'dotenv';
44
import yargs from 'yargs';
55
import * as aws from 'aws-sdk';
@@ -251,45 +251,38 @@ const getStackDetails = async (stackName: string, account: AWSAccountInfo, regio
251251
};
252252
};
253253

254-
const isRegionEnabled = async (config: unknown, region: string): Promise<boolean> => {
255-
try {
256-
const account = new Account(config);
257-
const response = await account.getRegionOptStatus({ RegionName: region }).promise();
258-
259-
return response.RegionOptStatus === 'ENABLED' || response.RegionOptStatus === 'ENABLED_BY_DEFAULT';
260-
} catch (e) {
261-
console.error(`Error checking region status: ${e}`);
262-
throw e;
263-
}
264-
};
265-
266254
const getStacks = async (account: AWSAccountInfo, region: string): Promise<StackInfo[]> => {
267255
const cfnClient = new aws.CloudFormation(getAWSConfig(account, region));
268-
269-
const regionEnabled = await isRegionEnabled(getAWSConfig(account), region);
270-
if (!regionEnabled) {
271-
return [];
256+
const results: StackInfo[] = [];
257+
let stacks;
258+
try {
259+
stacks = await cfnClient
260+
.listStacks({
261+
StackStatusFilter: [
262+
'CREATE_COMPLETE',
263+
'ROLLBACK_FAILED',
264+
'DELETE_FAILED',
265+
'UPDATE_COMPLETE',
266+
'UPDATE_ROLLBACK_FAILED',
267+
'UPDATE_ROLLBACK_COMPLETE',
268+
'IMPORT_COMPLETE',
269+
'IMPORT_ROLLBACK_FAILED',
270+
'IMPORT_ROLLBACK_COMPLETE',
271+
],
272+
})
273+
.promise();
274+
} catch (e) {
275+
if (e?.code === 'InvalidClientTokenId') {
276+
// Do not fail the cleanup and continue
277+
console.log(`Listing stacks for account ${account.accountId}-${region} failed with error with code ${e?.code}. Skipping.`);
278+
return results;
279+
} else {
280+
throw e;
281+
}
272282
}
273283

274-
const stacks = await cfnClient
275-
.listStacks({
276-
StackStatusFilter: [
277-
'CREATE_COMPLETE',
278-
'ROLLBACK_FAILED',
279-
'DELETE_FAILED',
280-
'UPDATE_COMPLETE',
281-
'UPDATE_ROLLBACK_FAILED',
282-
'UPDATE_ROLLBACK_COMPLETE',
283-
'IMPORT_COMPLETE',
284-
'IMPORT_ROLLBACK_FAILED',
285-
'IMPORT_ROLLBACK_COMPLETE',
286-
],
287-
})
288-
.promise();
289-
290284
// We are interested in only the root stacks that are deployed by amplify-cli
291285
const rootStacks = stacks.StackSummaries.filter(stack => !stack.RootId);
292-
const results: StackInfo[] = [];
293286
for (const stack of rootStacks) {
294287
try {
295288
const details = await getStackDetails(stack.StackName, account, region);

0 commit comments

Comments
 (0)