UNPKG

1.48 kBJavaScriptView Raw
1#!/usr/bin/env node
2
3'use strict';
4
5/**
6 * Two time script to remove deployed stage in order to upgrade beyond cumulus
7 * v1.13.
8 */
9const program = require('commander');
10const AWS = require('aws-sdk');
11const apigateway = new AWS.APIGateway();
12
13program.option('--prefix <name>', 'stack prefix to remove the stages from');
14program.option(
15 '--stage <name>',
16 'name of stage to delete from your apiGateway',
17 'dev'
18);
19
20program.option(
21 '--doit',
22 ('EXECUTE the commands to delete the stage from your prefixed stacks. Without'
23 + ' this flag, the script only describes the actions that would be taken.'),
24 false
25);
26
27program.parse(process.argv);
28
29const thisPrefix = (obj) => obj.name.startsWith(`${program.prefix}-`);
30
31const filterResponse = (response) => response.items.filter(thisPrefix);
32
33
34const removeStage = (restApi) => {
35 const param = {
36 restApiId: restApi.id,
37 stageName: program.stage
38 };
39
40 if (program.doit) {
41 console.log(
42 `DELETING stage: ${param.stageName} from ${restApi.name}(${
43 param.restApiId
44 }).`
45 );
46
47 return apigateway.deleteStage(param).promise();
48 }
49 console.log(
50 `will delete stage: ${param.stageName} from ${restApi.name}(${
51 param.restApiId
52 }).`
53 );
54 return Promise.resolve();
55};
56
57const removeEachStage = async (restApiList) => {
58 await Promise.all(restApiList.map(removeStage));
59};
60
61apigateway
62 .getRestApis({ limit: 500 })
63 .promise()
64 .then(filterResponse)
65 .then(removeEachStage);