npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cleanup-cloudformation-stacks

v1.0.0

Published

Typescript AWS cleanup script for CloudFormation Stacks

Downloads

3

Readme

CloudFormation Stack Cleaner

This is a Node.js script that uses the [@aws-sdk/client-cloudformation] package to list and delete CloudFormation stacks that match certain criteria.

Prerequisites

  • You need to have Node.js and NPM installed on your machine.
  • You need to have an AWS account and configure your credentials and region in your environment variables or in a configuration file. See [Setting Credentials in Node.js] for more details.

Installation

  • Clone this repository or download the source code as a ZIP file.
  • Navigate to the project folder and run npm install to install the dependencies.

Usage

  • Open the index.ts file and edit the stackNameConfig variable to specify the substring and position (prefix or suffix) that you want to use to filter the stacks. You can also add any exceptions that you want to exclude from the deletion. For example, if you want to delete all stacks that start with dev- except dev-main, you can use:
const stackNameConfig: StackNameConfig = {
  substring: 'dev-',
  substringPosition: 'prefix',
  exceptions: ['dev-main']
}

How it works

  • The script uses the CloudFormationClient class from the @aws-sdk/client-cloudformation package to interact with the AWS CloudFormation service. It creates an instance of the client with the region specified in the constructor.
  • The script uses the paginateListStacks function from the same package to get a paginator object that can iterate over the pages of the list stacks command. It passes the StackStatusFilter parameter to filter only the stacks that are in a complete state (created, updated, or rolled back).
  • The script loops over the pages of the paginator and pushes the stack summaries to an array. It then checks if the array is empty and throws an error if it is.
  • The script filters the array of stack summaries by applying the stackNameCondition function, which checks if the stack name matches the substring and position specified in the stackNameConfig variable and is not in the exceptions list. It also applies the isStaleStack function, which checks if the stack has a LastUpdatedTime property and if it is older than one day.
  • The script logs the filtered stack summaries and asks the user to confirm if they want to delete them. If the user enters y, it loops over the filtered stack summaries and calls the deleteStack function, which sends a delete stack command to the CloudFormation service with the stack name as the parameter. It then logs the deletion result. If the user enters n, it exits the script.