cloudmason 0.0.1 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/.github/workflows/CODEOWNERS +1 -0
  2. package/.github/workflows/main.yml +27 -27
  3. package/README.md +377 -25
  4. package/build.js +20 -20
  5. package/commands/delete.js +67 -28
  6. package/commands/helpers/cf.js +181 -117
  7. package/commands/helpers/common.js +82 -0
  8. package/commands/helpers/ec2.js +154 -40
  9. package/commands/helpers/params.js +231 -178
  10. package/commands/helpers/s3.js +186 -67
  11. package/commands/helpers/stacks/asg.yaml +420 -224
  12. package/commands/helpers/stacks/infra.yaml +102 -106
  13. package/commands/helpers/stacks.js +25 -25
  14. package/commands/index.html +22 -0
  15. package/commands/init_org.js +54 -61
  16. package/commands/inspect.js +40 -0
  17. package/commands/launch_app.js +80 -57
  18. package/commands/list_apps.js +21 -21
  19. package/commands/new_app.js +44 -50
  20. package/commands/new_instance.js +133 -186
  21. package/commands/reset_stack.js +27 -27
  22. package/commands/starter.js +21 -0
  23. package/commands/starters/asg_node/index.js +62 -0
  24. package/commands/starters/asg_node/mason.txt +1 -0
  25. package/commands/starters/asg_node/modules/appConfig.js +131 -0
  26. package/commands/starters/asg_node/package-lock.json +5877 -0
  27. package/commands/starters/asg_node/package.json +23 -0
  28. package/commands/starters/asg_node/public/css/favicon-16x16.png +0 -0
  29. package/commands/starters/asg_node/public/css/fonts/Lato-Bold.ttf +0 -0
  30. package/commands/starters/asg_node/public/css/fonts/Lato-Regular.ttf +0 -0
  31. package/commands/starters/asg_node/public/css/fonts/Montserrat-Var.ttf +0 -0
  32. package/commands/starters/asg_node/public/css/fonts/OpenSans.ttf +0 -0
  33. package/commands/starters/asg_node/public/css/fonts/bpmn.woff2 +0 -0
  34. package/commands/starters/asg_node/public/css/fonts/fonts.css +17 -0
  35. package/commands/starters/asg_node/public/css/index.css +9 -0
  36. package/commands/starters/asg_node/public/index.html +15 -0
  37. package/commands/starters/asg_node/public/js/index.js +5 -0
  38. package/commands/starters/asg_node/start.sh +4 -0
  39. package/commands/update_app.js +235 -272
  40. package/commands/update_stack.js +27 -0
  41. package/commands/utils.js +32 -32
  42. package/main.js +262 -220
  43. package/package.json +1 -28
  44. package/test.bat +16 -9
  45. package/commands/delete_app.js +0 -28
  46. package/commands/helpers/stacks/asg_draft.json +0 -321
@@ -0,0 +1 @@
1
+ * @kai-harvey
@@ -1,27 +1,27 @@
1
- name: Node.js Package
2
-
3
- on:
4
- pull_request:
5
- types:
6
- - closed
7
- branches:
8
- - 'release/**'
9
-
10
- jobs:
11
- if_merged:
12
- if: github.event.pull_request.merged == true
13
- runs-on: ubuntu-latest
14
- steps:
15
- - uses: actions/checkout@v3
16
- - uses: actions/setup-node@v3
17
- with:
18
- node-version: 16
19
- registry-url: https://registry.npmjs.org/
20
- - run: npm run build
21
- env:
22
- branch: ${{ github.base_ref }}
23
- build: ${{ github.run_number }}
24
- - run: npm ci
25
- - run: npm publish
26
- env:
27
- NODE_AUTH_TOKEN: ${{secrets.npm_token}}
1
+ name: Publish Node.js Package
2
+
3
+ on:
4
+ pull_request:
5
+ types:
6
+ - closed
7
+ branches:
8
+ - 'release/**'
9
+
10
+ jobs:
11
+ if_merged:
12
+ if: github.event.pull_request.merged == true
13
+ runs-on: ubuntu-latest
14
+ steps:
15
+ - uses: actions/checkout@v3
16
+ - uses: actions/setup-node@v3
17
+ with:
18
+ node-version: 16
19
+ registry-url: https://registry.npmjs.org/
20
+ - run: npm run build
21
+ env:
22
+ branch: ${{ github.base_ref }}
23
+ build: ${{ github.run_number }}
24
+ - run: npm ci
25
+ - run: npm publish
26
+ env:
27
+ NODE_AUTH_TOKEN: ${{secrets.npm_token}}
package/README.md CHANGED
@@ -1,25 +1,377 @@
1
- # Introduction
2
- TODO: Give a short introduction of your project. Let this section explain the objectives or the motivation behind this project.
3
-
4
- ## Sub Introduction
5
-
6
- ### Sub2 Introduction
7
-
8
-
9
- # Getting Started
10
- TODO: Guide users through getting your code up and running on their own system. In this section you can talk about:
11
- 1. Installation process
12
- 2. Software dependencies
13
- 3. Latest releases
14
- 4. API references
15
-
16
- # Build and Test
17
- TODO: Describe and show how to build your code and run the tests.
18
-
19
- # Contribute
20
- TODO: Explain how other users and developers can contribute to make your code better.
21
-
22
- If you want to learn more about creating good readme files then refer the following [guidelines](https://docs.microsoft.com/en-us/azure/devops/repos/git/create-a-readme?view=azure-devops). You can also seek inspiration from the below readme files:
23
- - [ASP.NET Core](https://github.com/aspnet/Home)
24
- - [Visual Studio Code](https://github.com/Microsoft/vscode)
25
- - [Chakra Core](https://github.com/Microsoft/ChakraCore)
1
+ Set up an AWS organization from scratch and deploy a static site or AMI-based EC2 application in just 4 commands.
2
+
3
+ The tool will handle everything from obtaining ACM certificates to building AMIs and deploying cloudformation stacks.
4
+
5
+ Can be used as a command line tool, or in a CI/CD pipeline.
6
+
7
+
8
+ # Quick Start
9
+
10
+ Get an Ec2 nodejs app up and running in 4 commands.
11
+
12
+ #### Step 1: Prereqs:
13
+
14
+ 1. Open an AWS account
15
+ 2. Download and set up the AWS CLI (or just set your AWS credentials with enviroment variables)
16
+ 3. Buy a domain to deploy apps to
17
+ 4. Run the following command to set up your org:
18
+ 1. `init-org -name MyOrg -region us-east-1`
19
+
20
+ #### Step 2: Set up an App
21
+
22
+ Run the command below to get a starter nodejs template
23
+
24
+ ```
25
+ mason starter -p ./myDesktop/HelloWorld -type asg
26
+ ```
27
+
28
+ #### Step 3: Add an App
29
+
30
+ ```
31
+ mason new-app -name MyFirstApp -type asg
32
+ new-instance -app MyFirstApp -domain myfirstapp.com -region us-east-2 -admin me@gmail.com
33
+ update-app -app MyFirstApp -v 1.0 -path ./myDesktop/HelloWorld
34
+ list-apps
35
+ ```
36
+ You now have an AMI and Cloudformation stack primed and ready to go.
37
+
38
+ #### Step 4: Launch it
39
+
40
+ ```
41
+ launch -app MyFirstApp -v 1.0 -domain myfirstapp.com
42
+ inspect -app MyFirstApp -domain myfirstapp.com -boot
43
+ ```
44
+
45
+ The `launch` command deploy the specified version of your application to the specified domain (instance).
46
+
47
+ It takes time to launch the app, so the `inspect` command will return the status of the cloudformation deployment. It will also return the console output from the boot script (aka User Data) when the first instance starts up.
48
+
49
+
50
+ # IMPORTANT!!!
51
+
52
+ - THIS APP DEPLOYS EC2 INSTANCES THAT ARE NOT FREE! IT WILL RESULT IN AWS CHARGES!
53
+ - Make sure to run `delete-instance` when you're done to avoid major surprises
54
+ - Your web application must serve on localhost:8080
55
+ - Use `inspect` ! It will return all console output of your application - very useful for debugging
56
+
57
+
58
+ # Architectures
59
+
60
+ ### AMI-Based Autoscaling Group Web App
61
+
62
+ To do
63
+
64
+ ### Cloudfront and S3 Static Site
65
+
66
+ To do
67
+
68
+
69
+
70
+
71
+ # Commands
72
+
73
+ Run `mason [command] -<options>`
74
+
75
+ | Command | Description |
76
+ | ---------------------------- | ------------------------------ |
77
+ | [init-org](###init-org) | Set up a new organization |
78
+ | [set-org](###set-org) | Set default org to an existing org |
79
+ | [new-app](###new-app) | Create a new application |
80
+ | [new-instance](###new-instance) | Create a new instance of an application |
81
+ | [update-app](###update-app) | Update the code and/or stack of an app version |
82
+ | [launch](###launch) | Deploy an app version to an instance |
83
+ | [inspect](###inspect) | Get cloudformation stack status and boot logs for an instance |
84
+ | [starter](###starter) | Get a starter template for a specified architecture type |
85
+ | [delete-instance](###delete-instance) | Delete an instance |
86
+ | [delete-app](###delete-app) | Delete an app |
87
+ | [update-stack](###update-stack) | Update cloudformation stac |
88
+ | [list-apps](###list-apps) | List all apps |
89
+ | [isvalid](###isvalid) | Check if a cloudformation template is valid |
90
+ | [zip](###zip) | Zip a folder |
91
+
92
+
93
+
94
+ ### init-org
95
+
96
+
97
+ `mason init-org -name -domain -region `
98
+
99
+ Sets up base infrastructure in a new AWS organization. This command should only be run once. To set up the tool with an existing org, use set-org.
100
+
101
+ | Parameter | Required | Type | Description |
102
+ | -------------- | ------------ | ---------------- | ---------------------------- |
103
+ | **name** | Y | String | Unique org Name. Letters only, no spaces |
104
+ | **domain** | Y | Valid domain | A base domain to use for core resources (e.g., cmason.io) |
105
+ | **region** | Y | AWS Region | Default AWS region for core resources (e.g., us-east-1) |
106
+
107
+
108
+ #### What it does
109
+
110
+ 1. Retrieves the default VPC ID
111
+ 2. Deploys a basic org infra stack
112
+ 1. S3 Bucket + policies for infra resources at `infra.[domain]`
113
+ 2. IAM Role, Instance Profile, and Security Group for Ec2 build agent
114
+ 3. SSM Parameters for oprg name, domain, instance profile, and security group
115
+
116
+
117
+
118
+
119
+ ### new-app
120
+
121
+ `mason new-app -name -type -node -py`
122
+
123
+ #### Params
124
+
125
+ | Parameter | Required | Type | Description |
126
+ | -------------- | ------------ | ---------------- | ---------------------------- |
127
+ | **name** | Y | String | Application name. Letters only |
128
+ | **type** | Y | Application Type | (Application architecture)[##Architectures]. See below for options. |
129
+ | node | n | Number | Version of nodejs to install on the base AMI. If set, app will run using nodejs |
130
+ | py | n | Number | Version of python to install on the base AMI. If set, app will run using python |
131
+
132
+
133
+ **Architecture Options**
134
+
135
+ - asg: autoscaling group
136
+ - static: static site
137
+
138
+ #### Examples
139
+
140
+ ```
141
+ mason new-app -name MyFirstApp -type asg -node
142
+ ```
143
+
144
+ #### What it does
145
+
146
+ 1. Builds a cloudformation stack with the appropriate boot script for nodejs or python
147
+ 2. Uploads the cloudformation template to the S3 infrastructure bucket
148
+ 3. Records the app name, type, and other key detail in SSM params
149
+
150
+
151
+
152
+
153
+ ### new-instance
154
+
155
+ `mason new-instance -app -name -domain -region -admin -max -ins -env`
156
+
157
+ Creates a new instance in a specified region. An instance is a deployment of an application. For example, MyFirstApp could have a test, UAT, and prod instance in us-east-1,us-east-2,and us-west-1.
158
+
159
+ Use -admin to specify the first admin user who will have access to set up other users.
160
+
161
+ #### Params
162
+
163
+ | Parameter | Required | Type | Description |
164
+ | -------------- | ------------ | ---------------- | ---------------------------- |
165
+ | **app** | Y | string | Name of existing application |
166
+ | **name** | Y | string | Instance name (ex., test, uat, etc). Letters only |
167
+ | **domain** | Y | string | Name of a subdomain or domain to deploy behind |
168
+ | **region** | Y | AWS region | region to deploy the instance in |
169
+ | **admin** | Y | email | email adress of first admin user |
170
+ | max | N | int | Maximum number of Ec2 instance to allow in the ASG. Higher number will result in better performance but possibly higher charges. Minimum is 2 to allow for proper refresh. |
171
+ | ins | N | string | Ec2 instance type. Default is t3.small |
172
+ | env | N | string | Enviroment (dev,test,prod). This value will be passed to the application. |
173
+
174
+
175
+ #### Examples
176
+
177
+ ```
178
+ mason new-app -name MyFirstApp -type asg -node
179
+ mason new-instance -app MyFirstApp -name uat -domain test.cmason.io -region us-east-2
180
+ mason new-instance -app MyFirstApp -name beta -domain beta.cmason.io -region us-west-1
181
+ ```
182
+
183
+
184
+ #### What it does
185
+
186
+ 1. Requests an ACM certificate for the domain if none exists (for HTTPS)
187
+ 2. Gets the default VPC ID and Subnets for the target region
188
+ 3. Saves deployment params to SSM for use when deploying the cloud formation template:
189
+ 1. ACM Certificate ID
190
+ 2. VPC Id
191
+ 3. Subnets and hosted zone ID
192
+
193
+
194
+
195
+ ### update-app
196
+
197
+ `mason update -app -v -path`
198
+
199
+ Updates the code for the specified application. This command will build a new AMI and update cloudformation stacks to point to the new AMI.
200
+ Path must lead to the root folder of your application. The bootscript will run with that directory as the root.
201
+
202
+ #### Params
203
+
204
+ | Parameter | Required | Type | Description |
205
+ | -------------- | ------------ | ---------------- | ---------------------------- |
206
+ | **app** | Y | string | Name of the existing app to update |
207
+ | **v** | Y | number | Version number to update |
208
+ | **path** | Y | Path to a folder or zip file containing the updated app code |
209
+
210
+
211
+ #### Examples
212
+
213
+ ```
214
+ mason update -app MyFirstApp -v 1.1 -path ./myfirstapp/src -stack ./myfirstapp/stack.json
215
+ ```
216
+
217
+ #### What it does
218
+
219
+ 1. Zips the folder (if not already zipped)
220
+ 2. Updates the cloudformation stack.yml file and uploads to S3
221
+ 3. Identifies the appropriate AWS Linux AMI ID for the base region
222
+ 4. Launches an EC2 instance, waits until it's ready, and then builds an AMI with the updated code package
223
+ 5. Terminates the EC2 instance
224
+ 6. Updates SSM with the updated AMI ID and build number
225
+
226
+
227
+
228
+
229
+ ### launch
230
+
231
+ `mason launch -app -v -i`
232
+
233
+ Launches a specific version of an application to an instance. For example, launch (deploy) MyFirstApp version 1.2 to test.cmason.io.
234
+
235
+
236
+ #### Params
237
+
238
+ | Parameter | Required | Type | Description |
239
+ | -------------- | ------------ | ---------------- | ---------------------------- |
240
+ | **app** | Y | string | Name of existing application to launch |
241
+ | **v** | Y | number | Version of the app to launch |
242
+ | **i** | Y | string | Name of the instance to deploy to |
243
+
244
+
245
+ #### Examples
246
+
247
+ ```
248
+ mason new-instance -app MyFirstApp -name uat -domain test.cmason.io -region us-east-2
249
+ mason update -app MyFirstApp -v 1.1 -path ./myfirstapp/src -stack ./myfirstapp/stack.jso
250
+ mason launch -app MyFirstApp -v 1.1 -i uat
251
+ ```
252
+
253
+
254
+ #### What it does
255
+
256
+ 1. Copies the AMI version created in the `update` command to the instance region
257
+ 2. Deploys the updated cloudformation stack
258
+
259
+
260
+
261
+ ### update-stack
262
+
263
+ `mason update-stack -app -v -default -stack`
264
+
265
+ Updates the default cloudformation template, or updates the template for a specific version.
266
+
267
+ #### Params
268
+
269
+ | Parameter | Required | Type | Description |
270
+ | -------------- | ------------ | ---------------- | ---------------------------- |
271
+ | **app** | Y | string | Name of the app to update |
272
+ | **stack** | Y | path | File path to updated cloudformation template |
273
+ | -v | N | number | Version number to update. Leave blank to update the default template |
274
+ | -default | flag | Include this flag to update the default cloudformation template for the app |
275
+
276
+
277
+ #### Examples
278
+
279
+ Update version 5 with a new stack
280
+
281
+ ```
282
+ mason update-stack -app MyFirstApp -v 1.0 -stack ../myfirstapp/stack.json
283
+ ```
284
+
285
+ Update the default cloduformation template for all future versions
286
+
287
+ ```
288
+ mason update-stack -app MyFirstApp -default -stack ../myfirstapp/stack.json
289
+ ```
290
+
291
+ #### What it does
292
+
293
+ 1. Uploads the specified stack file to S3
294
+
295
+
296
+
297
+ ### inspect
298
+
299
+ `mason inspect -app -domain [-run or -boot]`
300
+
301
+ Get stack status and EC2 console logs for an instance.
302
+ Useful for debugging issues with application boot up. Console output will
303
+
304
+ To get run logs, the application must write logs to S3 in the logs/run folder. See the starter nodejs app for an example.
305
+
306
+ #### Params
307
+
308
+ | Parameter | Required | Type | Description |
309
+ | -------------- | ------------ | ---------------- | ---------------------------- |
310
+ | **-app** | Y | string | App name |
311
+ | **-domain** | Y | string | Domain to inspect |
312
+ | -boot | N | null | If included, returns logs from the instance start up |
313
+ | -run | N | null | If included, returns run logs stored by the application in the s3 bucket at logs/run/* |
314
+
315
+ #### Examples
316
+
317
+ ```
318
+ mason inspect -app MyFirstApp -domain myfirstapp.com
319
+ ```
320
+
321
+
322
+ ### starter
323
+
324
+ `mason starter -type -l -path`
325
+
326
+ Sets up a starter application template for the specified architecture and language
327
+
328
+ #### Params
329
+
330
+ | Parameter | Required | Type | Description |
331
+ | -------------- | ------------ | ---------------- | ---------------------------- |
332
+ | **-type** | Y | string | Architecture of the application (asg, static, etc) |
333
+ | **-p** | Y | string | Path to output the project to |
334
+ | -l | Y | string | Language. py or node |
335
+
336
+ #### Examples
337
+
338
+ ```
339
+ mason starter -type asg -l node -path ../myfirstapp
340
+ ```
341
+
342
+
343
+
344
+
345
+
346
+ ## TODO
347
+
348
+ - [x] Run logs
349
+ - [x] Read token
350
+ - [x] Verify token
351
+ - [x] Get user groups
352
+ - [x] DDB connect
353
+ - [x] Fix starter routes
354
+ - [x] Add arguments for max ec2 instance and instance type
355
+ - [X] Customize boot script
356
+ - [x] Secure param permissions
357
+ - [X] Pass node/py versions
358
+ - [X] Pass version info to instance
359
+ - [X] Fix Delete App
360
+ - [X] Update default instance
361
+ - [X] Pass Env to instance
362
+ - [] Custom SES Config
363
+ - [X] Fix logs
364
+ - [] Add dev
365
+ - [] Add Admin
366
+ - [] Cloudtrails
367
+ - [] Static site
368
+ - [] Deregistering in home region
369
+ - [] cf-templates s3 bucket creation
370
+
371
+ ## OPEN ITEMS
372
+
373
+ - Custom auth domain
374
+ - AWS requires ACM cert in us-east-1 for custom Cognito auth domain. Cloudformation does not allow for cross-region resource creation
375
+ - [Github AWS Issue](https://github.com/aws-cloudformation/cloudformation-coverage-roadmap/issues/523)
376
+
377
+
package/build.js CHANGED
@@ -1,21 +1,21 @@
1
- const fs = require('fs');
2
-
3
- const pckg = JSON.parse(fs.readFileSync('./package.json'));
4
-
5
- const branch = process.env.branch;
6
- const build = process.env.build;
7
-
8
- console.log(`Branch: ${branch}`);
9
- console.log(`Build: ${build}`);
10
-
11
- const branchParts = branch.split('/');
12
- const lastPart = branchParts[branchParts.length - 1];
13
- const majorVersion = lastPart.replaceAll(/[^0-9\.]/g, '');
14
-
15
- const version = `${majorVersion}.${build}`;
16
-
17
- pckg.version = version;
18
-
19
- console.log(`Version: ${version}`);
20
-
1
+ const fs = require('fs');
2
+
3
+ const pckg = JSON.parse(fs.readFileSync('./package.json'));
4
+
5
+ const branch = process.env.branch;
6
+ const build = process.env.build;
7
+
8
+ console.log(`Branch: ${branch}`);
9
+ console.log(`Build: ${build}`);
10
+
11
+ const branchParts = branch.split('/');
12
+ const lastPart = branchParts[branchParts.length - 1];
13
+ const majorVersion = lastPart.replaceAll(/[^0-9\.]/g, '');
14
+
15
+ const version = `${majorVersion}.${build}`;
16
+
17
+ pckg.version = version;
18
+
19
+ console.log(`Version: ${version}`);
20
+
21
21
  fs.writeFileSync('./package.json', JSON.stringify(pckg));
@@ -1,29 +1,68 @@
1
- const CF = require('./helpers/cf');
2
- const Params = require('./helpers/params');
3
-
4
-
5
- exports.delete_instance = async function(args){
6
- // Get App
7
- const app = await Params.getApp(args.app);
8
- if (!app){
9
- console.log('Err: No app named ' + args.app);
10
- throw new Error('Err: No app named ' + args.app)
11
- }
12
- // Get Instance
13
- const targetInstance = app.instances.find(ins=>{ return ins.name.toLowerCase() == args.i.toLowerCase() });
14
- if (!targetInstance){ console.log(`No instance of ${args.app} named ${args.i}`); throw new Error('Invalid Instance')}
15
-
16
- // Delete Stack
17
- const stackName = (`${args.app}-${args.i}`).toLowerCase();
18
- console.log(`Deleting ${args.app} instance ${args.i} in ${targetInstance.region}`)
19
- const delOK = await CF.delete(stackName, targetInstance.region);
20
- if (delOK){
21
- console.log('Delete Successful')
22
- } else {
23
- return;
24
- }
25
-
26
- // Update Params
27
- await Params.deleteInstance(args.app,args.i);
28
- return true;
1
+ const CF = require('./helpers/cf');
2
+ const Params = require('./helpers/params');
3
+ const S3 = require('./helpers/s3');
4
+ const Common = require('./helpers/common');
5
+
6
+ exports.delete_app = async function(args){
7
+ // Get App
8
+ const app = await Params.getApp(args.app);
9
+ if (!app){
10
+ console.log('Err: No app named ' + args.app);
11
+ throw new Error('Err: No app named ' + args.app)
12
+ }
13
+ // Check Instances
14
+ if (app.instances.length > 0){
15
+ console.log('Err: App has instances. Delete instances first');
16
+ throw new Error('Err: App has instances. Delete instances first')
17
+ }
18
+
19
+ // Delete S3 Files
20
+ console.log('Deleting S3 Content for ' + args.app)
21
+ await S3.deleteAppFolder(args.app);
22
+
23
+ // Deregister AMIs
24
+ await Common.remove_app_amis(args.app,process.env.orgRegion);
25
+
26
+ // Update Params
27
+ console.log('Updating SSM Params')
28
+ await Params.deleteApp(args.app);
29
+ console.log('Succesfully Deleted ' + args.app)
30
+ return true;
31
+ }
32
+
33
+ exports.delete_instance = async function(args){
34
+ // Get App
35
+ const app = await Params.getApp(args.app);
36
+ if (!app){
37
+ console.log('Err: No app named ' + args.app);
38
+ throw new Error('Err: No app named ' + args.app)
39
+ }
40
+ // Get Instance
41
+ const targetInstance = app.instances.find(ins=>{ return ins.domain.toLowerCase() == args.domain.toLowerCase() });
42
+ if (!targetInstance){ console.log(`No instance of ${args.app} named ${args.domain}`); throw new Error('Invalid Instance')}
43
+
44
+ // Check if Stack Exists
45
+ const stackExists = await CF.stackExists(targetInstance.stackName,targetInstance.region);
46
+ console.log(`Stack Exists: ${stackExists}`)
47
+ if (stackExists === true){
48
+ // Delete S3 App Bucket
49
+ const bucketName = await CF.getStackResource('s3',targetInstance.stackName,targetInstance.region);
50
+ console.log('Emptying S3 Bucket for ' + bucketName)
51
+ await S3.emptyBucket(bucketName,targetInstance.region);
52
+ // Delete Stack
53
+ const stackName = targetInstance.stackName;
54
+ console.log(`Deleting ${args.app} instance ${args.domain} in ${targetInstance.region}`)
55
+ const delOK = await CF.delete(stackName, targetInstance.region);
56
+ if (delOK){
57
+ console.log('Delete Successful')
58
+ } else {
59
+ return;
60
+ }
61
+ // Deregister AMIs
62
+ await Common.prune_amis(args.app,targetInstance.version,targetInstance.region,true);
63
+ }
64
+
65
+ // Update Params
66
+ await Params.deleteInstance(args.app,args.domain);
67
+ return true;
29
68
  }