-
Notifications
You must be signed in to change notification settings - Fork 2
/
cli.ts
44 lines (40 loc) · 1.15 KB
/
cli.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import {
CloudFormationClient,
DescribeStacksCommand,
} from '@aws-sdk/client-cloudformation'
import { InvokeCommand, LambdaClient } from '@aws-sdk/client-lambda'
import { STACK_NAME } from './cdk/STACK_NAME.js'
const cf = new CloudFormationClient({})
const lambda = new LambdaClient({})
const { Stacks } = await cf.send(
new DescribeStacksCommand({ StackName: STACK_NAME }),
)
const { Outputs } = Stacks?.[0] ?? {}
await Promise.all(
(Outputs ?? []).map(
async ({ OutputKey: name, OutputValue: FunctionName }) => {
console.log(`[${name}]`, `Invoking`, FunctionName)
const { StatusCode, Payload } = await lambda.send(
new InvokeCommand({
FunctionName,
}),
)
console.log(`[${name}]`, StatusCode)
try {
const { pattern, resources }: { pattern: string; resources: string[] } =
JSON.parse(new TextDecoder().decode(Payload))
console.log(`[${name}]`, 'Pattern', pattern)
if (resources.length === 0) {
console.log(`[${name}]`, `No resources deleted`)
} else {
console.log(`[${name}]`, 'Deleted resources')
for (const res of resources) {
console.log(res)
}
}
} catch {
// pass
}
},
),
)