Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get all AWS Cloudformation stacks #1030

Merged
merged 2 commits into from
Mar 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 15 additions & 19 deletions extensions/amazon-aws/src/cloudformation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,20 @@ export default function ListStacks() {

useEffect(() => {
if (!preferences.region) return;
async function fetch() {
cloudformation.listStacks({}, async (err, data) => {
if (err) {
setState({
hasError: true,
loaded: false,
stacks: [],
});
} else {
setState({
hasError: false,
loaded: true,
stacks: data.StackSummaries || [],
});
}
});
async function fetchStacks(token?: string, stacks?: StackSummary[]): Promise<StackSummary[]> {
const { NextToken, StackSummaries } = await cloudformation.listStacks({ NextToken: token }).promise();
const combinedStacks = [...(stacks || []), ...(StackSummaries || [])];

if (NextToken) {
return fetchStacks(NextToken, combinedStacks);
}

return combinedStacks.filter((stack) => stack.StackStatus !== "DELETE_COMPLETE");
}
fetch();

fetchStacks()
.then((stacks) => setState({ hasError: false, loaded: true, stacks }))
.catch(() => setState({ hasError: true, loaded: false, stacks: [] }));
}, []);

if (state.hasError) {
Expand All @@ -50,7 +46,7 @@ export default function ListStacks() {
return (
<List isLoading={!state.loaded} searchBarPlaceholder="Filter stacks by name...">
{state.stacks.map((s) => (
<CloudFormationStack key={s.StackName} stack={s} />
<CloudFormationStack key={s.StackId} stack={s} />
))}
</List>
);
Expand All @@ -62,7 +58,7 @@ function CloudFormationStack({ stack }: { stack: StackSummary }) {
return (
<List.Item
id={stack.StackName}
key={stack.StackName}
key={stack.StackId}
title={stack.StackName}
accessoryTitle={stack.LastUpdatedTime ? new Date(stack.LastUpdatedTime).toLocaleString() : undefined}
actions={
Expand Down