Skip to content

Commit 3d1151c

Browse files
authored
fix: handle pagination when fetching region list in cleanup (#941)
* chore: test run Signed-off-by: Kevin Shan <[email protected]> * chore: test run Signed-off-by: Kevin Shan <[email protected]> * chore: test run Signed-off-by: Kevin Shan <[email protected]> * chore: test run Signed-off-by: Kevin Shan <[email protected]> * fix: disable pagination Signed-off-by: Kevin Shan <[email protected]> * chore: iterate the next token Signed-off-by: Kevin Shan <[email protected]> * chore: cleanup Signed-off-by: Kevin Shan <[email protected]> --------- Signed-off-by: Kevin Shan <[email protected]>
1 parent b115fe4 commit 3d1151c

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,23 @@ const getOrphanTestIamRoles = async (account: AWSAccountInfo): Promise<IamRoleIn
176176
const getRegionsEnabled = async (accountInfo: AWSAccountInfo): Promise<string[]> => {
177177
// Specify service region to avoid possible endpoint unavailable error
178178
const account = new Account({ ...accountInfo, region: 'us-east-1' });
179-
const response = await account.listRegions().promise();
180-
const enabledRegions = response.Regions.map(r =>
181-
r.RegionOptStatus === 'ENABLED' || r.RegionOptStatus === 'ENABLED_BY_DEFAULT' ? r.RegionName : null,
182-
).filter(Boolean);
183179

180+
const enabledRegions: string[] = [];
181+
let nextToken: string | undefined = undefined;
182+
183+
do {
184+
const input: Account.Types.ListRegionsRequest = {
185+
RegionOptStatusContains: ['ENABLED', 'ENABLED_BY_DEFAULT'],
186+
NextToken: nextToken,
187+
};
188+
189+
const response = await account.listRegions(input).promise();
190+
nextToken = response.NextToken;
191+
192+
enabledRegions.push(...response.Regions.map(r => r.RegionName).filter(Boolean));
193+
} while (nextToken);
194+
195+
console.log('All enabled regions fetched: ', enabledRegions);
184196
return enabledRegions;
185197
};
186198

0 commit comments

Comments
 (0)