Skip to content

Commit

Permalink
Add "CloudFormation Stacks" command to AWS extension (#950)
Browse files Browse the repository at this point in the history
* chore: update readme for amazon-aws

* feat: add cloudformation stacks AWS command

* refactor: ensure consistent file naming

* chore: update readme

* chore: add JonathanWbn to AWS contributors
  • Loading branch information
JonathanWbn committed Mar 2, 2022
1 parent 5150347 commit b3befd5
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 2 deletions.
3 changes: 3 additions & 0 deletions extensions/amazon-aws/README.md
Expand Up @@ -4,6 +4,9 @@

- List your EC2 Instances.
- List your SQS Queues.
- List your CodePipelines.
- List your CloudFormation Stacks.
- Access your AWS Console.

## Configuration

Expand Down
12 changes: 10 additions & 2 deletions extensions/amazon-aws/package.json
Expand Up @@ -6,12 +6,13 @@
"icon": "command-icon.png",
"author": "Falcon",
"contributors": [
"Hodglim"
"Hodglim",
"JonathanWbn"
],
"license": "MIT",
"commands": [
{
"name": "index",
"name": "ec2",
"title": "EC2 Instances",
"subtitle": "Amazon AWS",
"description": "List and Filter All your EC2 Instances",
Expand All @@ -37,6 +38,13 @@
"subtitle": "Amazon AWS",
"description": "Launch AWS console links",
"mode": "view"
},
{
"name": "cloudformation",
"title": "CloudFormation Stacks",
"subtitle": "Amazon AWS",
"description": "List All your CloudFormation Stacks",
"mode": "view"
}
],
"preferences": [
Expand Down
83 changes: 83 additions & 0 deletions extensions/amazon-aws/src/cloudformation.tsx
@@ -0,0 +1,83 @@
import { getPreferenceValues, ActionPanel, List, OpenInBrowserAction, Detail } from "@raycast/api";
import { useState, useEffect } from "react";
import * as AWS from "aws-sdk";
import { Preferences } from "./types";
import { StackSummary } from "aws-sdk/clients/cloudformation";

export default function ListStacks() {
const preferences: Preferences = getPreferenceValues();
AWS.config.update({ region: preferences.region });
const cloudformation = new AWS.CloudFormation({ apiVersion: "2016-11-15" });

const [state, setState] = useState<{
stacks: StackSummary[];
loaded: boolean;
hasError: boolean;
}>({
stacks: [],
loaded: false,
hasError: false,
});

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 || [],
});
}
});
}
fetch();
}, []);

if (state.hasError) {
return (
<Detail markdown="No valid [configuration and credential file](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html) found in your machine." />
);
}

return (
<List isLoading={!state.loaded} searchBarPlaceholder="Filter stacks by name...">
{state.stacks.map((s) => (
<CloudFormationStack key={s.StackName} stack={s} />
))}
</List>
);
}

function CloudFormationStack({ stack }: { stack: StackSummary }) {
const preferences: Preferences = getPreferenceValues();

return (
<List.Item
id={stack.StackName}
key={stack.StackName}
title={stack.StackName}
accessoryTitle={stack.LastUpdatedTime ? new Date(stack.LastUpdatedTime).toLocaleString() : undefined}
actions={
<ActionPanel>
<OpenInBrowserAction
title="Open in Browser"
url={
"https://console.aws.amazon.com/cloudformation/home?region=" +
preferences.region +
"#/stacks/stackinfo?stackId=" +
stack.StackId
}
/>
</ActionPanel>
}
/>
);
}
File renamed without changes.

0 comments on commit b3befd5

Please sign in to comment.