Skip to content

Commit 0ccb330

Browse files
committed
prettier
1 parent 69935e5 commit 0ccb330

File tree

5 files changed

+86
-91
lines changed

5 files changed

+86
-91
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cdk.out/
Lines changed: 52 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,52 @@
1-
2-
# aws-nuke for Weathertop
3-
4-
[aws-nuke](https://github.com/ekristen/aws-nuke) is an open-source tool that deletes non-default resources in a provided AWS account. It's implemented here in this directory using Cloud Development Kit (CDK) code that deploys the [official aws-nuke image](https://github.com/ekristen/aws-nuke/pkgs/container/aws-nuke) to an AWS Lambda function.
5-
6-
## ⚠ Important
7-
This is a very destructive tool! It should not be deployed without fully understanding the impact it will have on your AWS accounts.
8-
Please use caution and configure this tool to delete unused resources only in your lower test/sandbox environment accounts.
9-
10-
## Overview
11-
12-
This CDK stack is defined in [account_nuker.ts](account_nuker.ts). It includes:
13-
- A Docker-based Lambda function with ARM64 architecture and 1GB memory
14-
- An IAM role with administrative permissions for the Lambda's nuking function
15-
- An EventBridge rule that triggers the function every Sunday at midnight
16-
17-
More specifically, this Lambda function is built from a [Dockerfile](Dockerfile) and runs with a 15-minute timeout. It contains a [nuke_generic_config.yml](nuke_generic_config.yaml) config and executes a [run.sh](run.sh) when invoked every Sunday at midnight UTC.
18-
19-
![infrastructure-overview](nuke-overview.png)
20-
21-
## Prerequisites
22-
1. **Non-Prod AWS Account Alias**: A non-prod account alias must exist in target account. Set the alias by running `python create_account_alias.py weathertop-test` or following [these instructions](https://docs.aws.amazon.com/IAM/latest/UserGuide/account-alias-create.html).
23-
24-
## Setup and Installation
25-
For multi-account deployments, please use the [deploy.py](../../../DEPLOYMENT.md#option-1-using-deploypy) script.
26-
27-
For single-account deployment, you can just run:
28-
```sh
29-
cdk bootstrap && cdk deploy
30-
```
31-
32-
Note a successful stack creation, e.g.:
33-
34-
```bash
35-
NukeStack: success: Published 956fbd116734e79edb987e767fe7f45d0b97e2123456789109103f80ba4c1:123456789101-us-east-1
36-
Stack undefined
37-
NukeStack: deploying... [1/1]
38-
NukeStack: creating CloudFormation changeset...
39-
40-
✅ NukeStack
41-
42-
✨ Deployment time: 27.93s
43-
44-
Stack ARN:
45-
arn:aws:cloudformation:us-east-1:123456789101:stack/NukeStack/9835cc20-d358-11ef-bccf-123407dc82dd
46-
47-
✨ Total time: 33.24s
48-
```
1+
# aws-nuke for Weathertop
2+
3+
[aws-nuke](https://github.com/ekristen/aws-nuke) is an open-source tool that deletes non-default resources in a provided AWS account. It's implemented here in this directory using Cloud Development Kit (CDK) code that deploys the [official aws-nuke image](https://github.com/ekristen/aws-nuke/pkgs/container/aws-nuke) to an AWS Lambda function.
4+
5+
## ⚠ Important
6+
7+
This is a very destructive tool! It should not be deployed without fully understanding the impact it will have on your AWS accounts.
8+
Please use caution and configure this tool to delete unused resources only in your lower test/sandbox environment accounts.
9+
10+
## Overview
11+
12+
This CDK stack is defined in [account_nuker.ts](account_nuker.ts). It includes:
13+
14+
- A Docker-based Lambda function with ARM64 architecture and 1GB memory
15+
- An IAM role with administrative permissions for the Lambda's nuking function
16+
- An EventBridge rule that triggers the function every Sunday at midnight
17+
18+
More specifically, this Lambda function is built from a [Dockerfile](Dockerfile) and runs with a 15-minute timeout. It contains a [nuke_generic_config.yml](nuke_generic_config.yaml) config and executes a [run.sh](run.sh) when invoked every Sunday at midnight UTC.
19+
20+
![infrastructure-overview](nuke-overview.png)
21+
22+
## Prerequisites
23+
24+
1. **Non-Prod AWS Account Alias**: A non-prod account alias must exist in target account. Set the alias by running `python create_account_alias.py weathertop-test` or following [these instructions](https://docs.aws.amazon.com/IAM/latest/UserGuide/account-alias-create.html).
25+
26+
## Setup and Installation
27+
28+
For multi-account deployments, please use the [deploy.py](../../../DEPLOYMENT.md#option-1-using-deploypy) script.
29+
30+
For single-account deployment, you can just run:
31+
32+
```sh
33+
cdk bootstrap && cdk deploy
34+
```
35+
36+
Note a successful stack creation, e.g.:
37+
38+
```bash
39+
NukeStack: success: Published 956fbd116734e79edb987e767fe7f45d0b97e2123456789109103f80ba4c1:123456789101-us-east-1
40+
Stack undefined
41+
NukeStack: deploying... [1/1]
42+
NukeStack: creating CloudFormation changeset...
43+
44+
✅ NukeStack
45+
46+
✨ Deployment time: 27.93s
47+
48+
Stack ARN:
49+
arn:aws:cloudformation:us-east-1:123456789101:stack/NukeStack/9835cc20-d358-11ef-bccf-123407dc82dd
50+
51+
✨ Total time: 33.24s
52+
```
Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
3-
import * as cdk from 'aws-cdk-lib';
4-
import * as events from 'aws-cdk-lib/aws-events';
5-
import * as targets from 'aws-cdk-lib/aws-events-targets';
6-
import * as iam from 'aws-cdk-lib/aws-iam';
7-
import * as path from 'path';
3+
import * as cdk from "aws-cdk-lib";
4+
import * as events from "aws-cdk-lib/aws-events";
5+
import * as targets from "aws-cdk-lib/aws-events-targets";
6+
import * as iam from "aws-cdk-lib/aws-iam";
7+
import * as path from "path";
88
import * as lambda from "aws-cdk-lib/aws-lambda";
9-
import { Duration, Stack, StackProps } from 'aws-cdk-lib';
10-
import { Construct } from 'constructs';
11-
import { DockerImageCode, DockerImageFunction } from 'aws-cdk-lib/aws-lambda';
9+
import { Duration, Stack, StackProps } from "aws-cdk-lib";
10+
import { Construct } from "constructs";
11+
import { DockerImageCode, DockerImageFunction } from "aws-cdk-lib/aws-lambda";
1212

1313
export interface NukeStackProps extends cdk.StackProps {
1414
awsNukeDryRunFlag?: string;
@@ -21,30 +21,33 @@ class NukeStack extends cdk.Stack {
2121

2222
constructor(scope: Construct, id: string, props?: StackProps) {
2323
super(scope, id, props);
24-
2524

2625
// Lambda Function role
27-
this.nukeLambdaRole = new iam.Role(this, 'NukeLambdaRole', {
28-
assumedBy: new iam.ServicePrincipal('lambda.amazonaws.com'),
26+
this.nukeLambdaRole = new iam.Role(this, "NukeLambdaRole", {
27+
assumedBy: new iam.ServicePrincipal("lambda.amazonaws.com"),
2928
managedPolicies: [
30-
iam.ManagedPolicy.fromAwsManagedPolicyName('AdministratorAccess'),
29+
iam.ManagedPolicy.fromAwsManagedPolicyName("AdministratorAccess"),
3130
],
3231
});
3332

3433
// Create the Lambda function
35-
const lambdaFunction = new DockerImageFunction(this, 'docker-lambda-function', {
36-
functionName: "docker-lambda-fn",
37-
code: DockerImageCode.fromImageAsset(path.join(__dirname)),
38-
memorySize: 1024,
39-
timeout: Duration.minutes(15),
40-
architecture: lambda.Architecture.ARM_64,
41-
description: "This is dockerized AWS Lambda function",
42-
role: this.nukeLambdaRole
43-
});
34+
const lambdaFunction = new DockerImageFunction(
35+
this,
36+
"docker-lambda-function",
37+
{
38+
functionName: "docker-lambda-fn",
39+
code: DockerImageCode.fromImageAsset(path.join(__dirname)),
40+
memorySize: 1024,
41+
timeout: Duration.minutes(15),
42+
architecture: lambda.Architecture.ARM_64,
43+
description: "This is dockerized AWS Lambda function",
44+
role: this.nukeLambdaRole,
45+
},
46+
);
4447

4548
// Create EventBridge rule to trigger the Lambda function weekly
46-
const rule = new events.Rule(this, 'WeeklyTriggerRule', {
47-
schedule: events.Schedule.expression('cron(0 0 ? * SUN *)') // Runs at 00:00 every Sunday
49+
const rule = new events.Rule(this, "WeeklyTriggerRule", {
50+
schedule: events.Schedule.expression("cron(0 0 ? * SUN *)"), // Runs at 00:00 every Sunday
4851
});
4952

5053
// Add the Lambda function as a target for the EventBridge rule
@@ -53,10 +56,10 @@ class NukeStack extends cdk.Stack {
5356
}
5457

5558
const app = new cdk.App();
56-
new NukeStack(app, 'NukeStack', {
59+
new NukeStack(app, "NukeStack", {
5760
env: {
5861
account: process.env.CDK_DEFAULT_ACCOUNT,
5962
region: process.env.CDK_DEFAULT_REGION,
6063
},
61-
terminationProtection: true
64+
terminationProtection: true,
6265
});

.tools/test/stacks/nuke/typescript/cdk.json

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
{
22
"app": "npx ts-node --prefer-ts-exts account_nuker.ts",
33
"watch": {
4-
"include": [
5-
"**"
6-
],
4+
"include": ["**"],
75
"exclude": [
86
"README.md",
97
"cdk*.json",
@@ -19,10 +17,7 @@
1917
"context": {
2018
"@aws-cdk/aws-lambda:recognizeLayerVersion": true,
2119
"@aws-cdk/core:checkSecretUsage": true,
22-
"@aws-cdk/core:target-partitions": [
23-
"aws",
24-
"aws-cn"
25-
],
20+
"@aws-cdk/core:target-partitions": ["aws", "aws-cn"],
2621
"@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true,
2722
"@aws-cdk/aws-iam:minimizePolicies": true,
2823
"@aws-cdk/aws-apigateway:disableCloudWatchRole": true,

.tools/test/stacks/nuke/typescript/tsconfig.json

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22
"compilerOptions": {
33
"target": "ES2020",
44
"module": "commonjs",
5-
"lib": [
6-
"es2020",
7-
"dom"
8-
],
5+
"lib": ["es2020", "dom"],
96
"declaration": true,
107
"strict": true,
118
"noImplicitAny": true,
@@ -20,12 +17,7 @@
2017
"inlineSources": true,
2118
"experimentalDecorators": true,
2219
"strictPropertyInitialization": false,
23-
"typeRoots": [
24-
"./node_modules/@types"
25-
]
20+
"typeRoots": ["./node_modules/@types"]
2621
},
27-
"exclude": [
28-
"node_modules",
29-
"cdk.out"
30-
]
22+
"exclude": ["node_modules", "cdk.out"]
3123
}

0 commit comments

Comments
 (0)