|
1 |
| -import type { CloudFormationClient } from '@aws-sdk/client-cloudformation'; |
| 1 | +import { |
| 2 | + type ListStackResourcesCommand as ListStackResourcesCommandType, |
| 3 | + type StackResourceSummary, |
| 4 | + type CloudFormationClient, |
| 5 | +} from '@aws-sdk/client-cloudformation'; |
2 | 6 | import { AwsCredentials } from './awsCredentials.js';
|
3 | 7 | import { AwsConfiguration } from './types/awsConfiguration.js';
|
4 | 8 | import { Logger } from './logger.js';
|
@@ -72,15 +76,28 @@ async function getCloudFormationResources(
|
72 | 76 | const { ListStackResourcesCommand } = await import(
|
73 | 77 | '@aws-sdk/client-cloudformation'
|
74 | 78 | );
|
75 |
| - const command = new ListStackResourcesCommand({ |
76 |
| - StackName: stackName, |
77 |
| - }); |
78 |
| - const cloudFormationClient = await getCloudFormationClient(awsConfiguration); |
| 79 | + |
| 80 | + const cloudFormationClient: CloudFormationClient = |
| 81 | + await getCloudFormationClient(awsConfiguration); |
79 | 82 |
|
80 | 83 | try {
|
81 |
| - const response = await cloudFormationClient.send(command); |
| 84 | + let nextToken: string | undefined = undefined; |
| 85 | + const items: StackResourceSummary[] = []; |
| 86 | + do { |
| 87 | + const command: ListStackResourcesCommandType = |
| 88 | + new ListStackResourcesCommand({ |
| 89 | + StackName: stackName, |
| 90 | + NextToken: nextToken, |
| 91 | + }); |
| 92 | + |
| 93 | + const response = await cloudFormationClient.send(command); |
82 | 94 |
|
83 |
| - return response; |
| 95 | + if (response.StackResourceSummaries) { |
| 96 | + items.push(...response.StackResourceSummaries); |
| 97 | + } |
| 98 | + nextToken = response.NextToken; |
| 99 | + } while (nextToken); |
| 100 | + return items; |
84 | 101 | } catch (error: any) {
|
85 | 102 | if (error.name === 'ValidationError') {
|
86 | 103 | Logger.error(
|
@@ -113,7 +130,7 @@ async function getLambdasInStack(
|
113 | 130 | stackName,
|
114 | 131 | awsConfiguration,
|
115 | 132 | );
|
116 |
| - const lambdaResources = response?.StackResourceSummaries?.filter( |
| 133 | + const lambdaResources = response?.filter( |
117 | 134 | (resource) => resource.ResourceType === 'AWS::Lambda::Function',
|
118 | 135 | );
|
119 | 136 |
|
|
0 commit comments