2022-04-07 00:45:15 +00:00
|
|
|
import AWS from 'aws-sdk';
|
2022-04-07 19:29:26 +00:00
|
|
|
import { CliFunction } from '../../../../cli/cli-functions-repository';
|
2022-04-07 00:45:15 +00:00
|
|
|
import Input from '../../../../input';
|
|
|
|
|
import CloudRunnerLogger from '../../../services/cloud-runner-logger';
|
|
|
|
|
|
|
|
|
|
export class AWSCLICommands {
|
|
|
|
|
@CliFunction(`garbage-collect-aws`, `garbage collect aws`)
|
|
|
|
|
static async garbageCollectAws() {
|
|
|
|
|
process.env.AWS_REGION = Input.region;
|
|
|
|
|
CloudRunnerLogger.log(`Cloud Formation stacks`);
|
2022-04-07 01:50:32 +00:00
|
|
|
const CF = new AWS.CloudFormation();
|
|
|
|
|
const stacks =
|
|
|
|
|
(await CF.listStacks().promise()).StackSummaries?.filter((_x) => _x.StackStatus !== 'DELETE_COMPLETE') || [];
|
2022-04-07 00:45:15 +00:00
|
|
|
for (const element of stacks) {
|
|
|
|
|
CloudRunnerLogger.log(JSON.stringify(element, undefined, 4));
|
2022-04-07 01:50:32 +00:00
|
|
|
if (Input.cloudRunnerTests) await CF.deleteStack({ StackName: element.StackName }).promise();
|
2022-04-07 00:45:15 +00:00
|
|
|
}
|
|
|
|
|
CloudRunnerLogger.log(`ECS Clusters`);
|
|
|
|
|
const ecs = new AWS.ECS();
|
2022-04-07 01:50:32 +00:00
|
|
|
const clusters = (await ecs.listClusters().promise()).clusterArns || [];
|
|
|
|
|
if (stacks === undefined) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
for (const element of clusters) {
|
|
|
|
|
const input: AWS.ECS.ListTasksRequest = {
|
|
|
|
|
cluster: element,
|
|
|
|
|
};
|
|
|
|
|
CloudRunnerLogger.log(JSON.stringify(await ecs.listTasks(input).promise(), undefined, 4));
|
|
|
|
|
}
|
2022-04-07 00:45:15 +00:00
|
|
|
}
|
|
|
|
|
}
|