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

cdk-self-destruct

v1.2.5

Published

A construct that allows you to self-destruct your AWS resources in a given stack

Downloads

3,327

Readme

cdk-self-destruct

npm version Pipeline

A cdk construct for destroying CDK environments, which may be used in automated testing.

All resources in the stack may be set to be destroyed regardless of their RemovalPolicy or they may be retained.

With its scheduling feature for stack destruction, you can easily set a time and date or generate a url for the automatic removal of unnecessary stacks, freeing up resources and optimizing the testing workflow. It also removes resources that are impeding stack deletion, such as non-empty S3 buckets.

Inspired by cdk-time-bomb, rewritten with aws-cdk v2 and the new AWS EventBridge Scheduler.

Installing

requires aws-cdk: "^2.51.0"

npm install cdk-self-destruct

# or

yarn add cdk-self-destruct

Usage

Include it at the end of your stack. Behind the scenes it uses CDK Aspects to capture all resources automatically.

import { type StackProps, Stack, Duration } from 'aws-cdk-lib'
import { type Construct } from 'constructs'
import { SelfDestruct } from 'cdk-self-destruct'

export class AwesomeStack extends Stack {
  public constructor(scope: Construct, id: string, props: StackProps) {
    super(scope, id, props)

    new SelfDestruct(this, 'SelfDestruct', {
      defaultBehavior: {
        destoryAllResources: true,
        purgeResourceDependencies: true,
      },
      trigger: {
        scheduled: {
          afterDuration: Duration.days(1),
          enabled: true,
        },
      },
    })
  }
}

Features

  1. Set RemovalPolicy for all resources inside a stack
  2. Destroy resource dependencies that are blocking the stack deletion
    • Purge S3 buckets before deletion
    • Stop all running state-machine executions
    • Delete automatically generated cloudwatch logs for lambda functions
    • more coming soon
  3. Schedule stack deletions after a given duration or at a given timestamp
  4. Create a Lambda function URL to delete the stack easily from the pipeline

Options

Select per individual resource

A list of all available options can be found here

new SelfDestruct(this, 'SelfDestruct', {
  // ...
  byResource: {
    resourcesToDestroy: ['AWS::S3::Bucket'],
    resourcesToRetain: ['AWS::DynamoDB::Table'],
  },
})

Schedule for a given Date

Stack deletion may be scheduled for a given UTC timestamp.

new SelfDestruct(this, 'SelfDestruct', {
  // ...
  trigger: {
    scheduled: {
      atTimestamp: new Date('2023-01-01T00:00:00Z').getTime(),
      enabled: true,
    },
  },
})

Invoke via a lambda function url

Function urls allow to start the stack deletion manually via an http request. Authentication is available via IAM or via unauthenticated requests.

new SelfDestruct(this, 'SelfDestruct', {
  // ...
  trigger: {
    addFunctionUrl: {
      cloudformationOutput: {
        description: 'URL to invoke the self-destruct function',
        exportName: 'SelfDestructUrl',
      },
      enabled: true,
      options: {
        // Allow unauthenticated requests
        authType: FunctionUrlAuthType.NONE,
      },
    },
  },
})

Perform additional cleanup

Remove additional resources created by AWS services that are not included in the cdk stack.

Currently supported:

  • Cloudwatch log groups implicitly created by aws lambda functions
new SelfDestruct(this, 'SelfDestruct', {
  // ...
  additionalCleanup: {
    cleanupLambdaLogGroups: true,
  },
})