1 |
|
2 |
|
3 | ### Table of Contents
|
4 |
|
5 | - [Config](#config)
|
6 | - [parse](#parse)
|
7 | - [flatten](#flatten)
|
8 | - [Kes](#kes)
|
9 | - [updateSingleLambda](#updatesinglelambda)
|
10 | - [compileCF](#compilecf)
|
11 | - [uploadToS3](#uploadtos3)
|
12 | - [uploadCF](#uploadcf)
|
13 | - [waitFor](#waitfor)
|
14 | - [cloudFormation](#cloudformation)
|
15 | - [validateTemplate](#validatetemplate)
|
16 | - [describeCF](#describecf)
|
17 | - [deleteCF](#deletecf)
|
18 | - [opsStack](#opsstack)
|
19 | - [upsertStack](#upsertstack)
|
20 | - [deployStack](#deploystack)
|
21 | - [createStack](#createstack)
|
22 | - [updateStack](#updatestack)
|
23 | - [deleteStack](#deletestack)
|
24 | - [Lambda](#lambda)
|
25 | - [buildS3Path](#builds3path)
|
26 | - [getHash](#gethash)
|
27 | - [zipLambda](#ziplambda)
|
28 | - [uploadLambda](#uploadlambda)
|
29 | - [zipAndUploadLambda](#zipanduploadlambda)
|
30 | - [process](#process)
|
31 | - [updateSingleLambda](#updatesinglelambda-1)
|
32 | - [localRun](#localrun)
|
33 | - [zip](#zip)
|
34 | - [exec](#exec)
|
35 | - [configureAws](#configureaws)
|
36 | - [fileToString](#filetostring)
|
37 | - [mergeYamls](#mergeyamls)
|
38 | - [determineKesClass](#determinekesclass)
|
39 | - [failure](#failure)
|
40 | - [success](#success)
|
41 | - [getSystemBucket](#getsystembucket)
|
42 |
|
43 | ## Config
|
44 |
|
45 | This class handles reading and parsing configuration files.
|
46 | It primarily reads `config.yml` and `.env` files
|
47 |
|
48 | **Parameters**
|
49 |
|
50 | - `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** a js object that includes required options.
|
51 | - `options.stack` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** the stack name
|
52 | - `options.deployment` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the deployment name (optional, default `null`)
|
53 | - `options.region` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the aws region (optional, default `'us-east-1'`)
|
54 | - `options.profile` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the profile name (optional, default `null`)
|
55 | - `options.kesFolder` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the path to the kes folder (optional, default `'.kes'`)
|
56 | - `options.configFile` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the path to the config.yml (optional, default `'config.yml'`)
|
57 | - `options.envFile` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the path to the .env file (optional, default `'.env'`)
|
58 | - `options.cfFile` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the path to the CF template (optional, default `'cloudformation.template.yml'`)
|
59 | - `stack` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Stack name
|
60 | - `deployment` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Deployment name
|
61 | - `configFile` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to the config.yml file
|
62 | - `envFile` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to the .env file (optional)
|
63 |
|
64 | **Examples**
|
65 |
|
66 | ```javascript
|
67 | const config = new Config('mystack', 'dev', '.kes/config.yml', '.kes/.env');
|
68 | ```
|
69 |
|
70 | ### parse
|
71 |
|
72 | Main method of the class. It parses a configuration and returns it
|
73 | as a JS object.
|
74 |
|
75 | **Examples**
|
76 |
|
77 | ```javascript
|
78 | const configInstance = new Config(null, null, 'path/to/config.yml', 'path/to/.env');
|
79 | config = configInstance.parse();
|
80 | ```
|
81 |
|
82 | Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** the configuration object
|
83 |
|
84 | ### flatten
|
85 |
|
86 | Return a javascript object (not a class instance) of the
|
87 | config class
|
88 |
|
89 | Returns **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** a javascript object version of the class
|
90 |
|
91 | ## Kes
|
92 |
|
93 | The main Kes class. This class is used in the command module to create
|
94 | the CLI interface for kes. This class can be extended in order to override
|
95 | and modify the behavior of kes cli.
|
96 |
|
97 | **Parameters**
|
98 |
|
99 | - `config` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** an instance of the Config class (config.js)
|
100 |
|
101 | **Examples**
|
102 |
|
103 | ```javascript
|
104 | const { Kes, Config } = require('kes');
|
105 |
|
106 | const options = { stack: 'myStack' };
|
107 | const config = new Config(options);
|
108 | const kes = new Kes(config);
|
109 |
|
110 | // create a new stack
|
111 | kes.deployStack()
|
112 | .then(() => describeCF())
|
113 | .then(() => updateSingleLambda('myLambda'))
|
114 | .catch(e => console.log(e));
|
115 | ```
|
116 |
|
117 | ### updateSingleLambda
|
118 |
|
119 | Updates code of a deployed lambda function
|
120 |
|
121 | **Parameters**
|
122 |
|
123 | - `name` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the name of the lambda function defined in config.yml
|
124 |
|
125 | Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** returns the promise of an AWS response object
|
126 |
|
127 | ### compileCF
|
128 |
|
129 | Compiles a CloudFormation template in Yaml format.
|
130 |
|
131 | Reads the configuration yaml from `.kes/config.yml`.
|
132 |
|
133 | Writes the template to `.kes/cloudformation.yml`.
|
134 |
|
135 | Uses `.kes/cloudformation.template.yml` as the base template
|
136 | for generating the final CF template.
|
137 |
|
138 | Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** returns the promise of an AWS response object
|
139 |
|
140 | ### uploadToS3
|
141 |
|
142 | This is just a wrapper around AWS s3.upload method.
|
143 | It uploads a given string to a S3 object.
|
144 |
|
145 | **Parameters**
|
146 |
|
147 | - `bucket` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the s3 bucket name
|
148 | - `key` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the path and name of the object
|
149 | - `body` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the content of the object
|
150 |
|
151 | Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** returns the promise of an AWS response object
|
152 |
|
153 | ### uploadCF
|
154 |
|
155 | Uploads the Cloud Formation template to a given S3 location
|
156 |
|
157 | Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** returns the promise of an AWS response object
|
158 |
|
159 | ### waitFor
|
160 |
|
161 | Wait for the current stack and log the current outcome
|
162 |
|
163 | **Parameters**
|
164 |
|
165 | - `wait`
|
166 |
|
167 | Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** undefined
|
168 |
|
169 | ### cloudFormation
|
170 |
|
171 | Calls CloudFormation's update-stack or create-stack methods
|
172 |
|
173 | Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** returns the promise of an AWS response object
|
174 |
|
175 | ### validateTemplate
|
176 |
|
177 | Validates the CF template
|
178 |
|
179 | Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** returns the promise of an AWS response object
|
180 |
|
181 | ### describeCF
|
182 |
|
183 | Describes the cloudformation stack deployed
|
184 |
|
185 | Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** returns the promise of an AWS response object
|
186 |
|
187 | ### deleteCF
|
188 |
|
189 | Deletes the current stack
|
190 |
|
191 | Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** undefined
|
192 |
|
193 | ### opsStack
|
194 |
|
195 | Generic create/update method for CloudFormation
|
196 |
|
197 | Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** returns the promise of an AWS response object
|
198 |
|
199 | ### upsertStack
|
200 |
|
201 | [Deprecated] Creates a CloudFormation stack for the class instance
|
202 | If exists, will update the existing one
|
203 |
|
204 | Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** returns the promise of an AWS response object
|
205 |
|
206 | ### deployStack
|
207 |
|
208 | Creates a CloudFormation stack for the class instance
|
209 | If exists, will update the existing one
|
210 |
|
211 | Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** returns the promise of an AWS response object
|
212 |
|
213 | ### createStack
|
214 |
|
215 | [Deprecated] Creates a CloudFormation stack for the class instance
|
216 |
|
217 | Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** returns the promise of an AWS response object
|
218 |
|
219 | ### updateStack
|
220 |
|
221 | [Deprecated] Updates an existing CloudFormation stack for the class instance
|
222 |
|
223 | Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** returns the promise of an AWS response object
|
224 |
|
225 | ### deleteStack
|
226 |
|
227 | Deletes the main stack
|
228 |
|
229 | Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** returns the promise of an AWS response object
|
230 |
|
231 | ## Lambda
|
232 |
|
233 | Copy, zip and upload lambda functions to S3
|
234 |
|
235 | **Parameters**
|
236 |
|
237 | - `config` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** the configuration object
|
238 | - `kesFolder` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the path to the `.kes` folder
|
239 | - `bucket` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the S3 bucket name
|
240 | - `key` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the main folder to store the data in the bucket (stack)
|
241 |
|
242 | ### buildS3Path
|
243 |
|
244 | Adds hash value, bucket name, and remote and local paths
|
245 | for lambdas that have source value.
|
246 |
|
247 | If a s3Source is usaed, only add remote and bucket values
|
248 |
|
249 | **Parameters**
|
250 |
|
251 | - `lambda` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** the lambda object
|
252 |
|
253 | Returns **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** the lambda object
|
254 |
|
255 | ### getHash
|
256 |
|
257 | calculate the hash value for a given path
|
258 |
|
259 | **Parameters**
|
260 |
|
261 | - `folderName` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** directory path
|
262 | - `method` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** hash type, default to shasum
|
263 |
|
264 | Returns **[buffer](https://nodejs.org/api/buffer.html)** hash value
|
265 |
|
266 | ### zipLambda
|
267 |
|
268 | zip a given lambda function source code
|
269 |
|
270 | **Parameters**
|
271 |
|
272 | - `lambda` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** the lambda object
|
273 |
|
274 | Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** returns the promise of the lambda object
|
275 |
|
276 | ### uploadLambda
|
277 |
|
278 | Uploads the zipped lambda code to a given s3 bucket
|
279 | if the zip file already exists on S3 it skips the upload
|
280 |
|
281 | **Parameters**
|
282 |
|
283 | - `lambda` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** the lambda object. It must have the following properties
|
284 | - `lambda.bucket` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the s3 buckt name
|
285 | - `lambda.remote` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the lambda code's key (path and filename) on s3
|
286 | - `lambda.local` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the zip files location on local machine
|
287 |
|
288 | Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** returns the promise of updated lambda object
|
289 |
|
290 | ### zipAndUploadLambda
|
291 |
|
292 | Zips and Uploads a lambda function. If the source of the function
|
293 | is already zipped and uploaded, it skips the step only updates the
|
294 | lambda config object.
|
295 |
|
296 | **Parameters**
|
297 |
|
298 | - `lambda` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** the lambda object.
|
299 |
|
300 | Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** returns the promise of updated lambda object
|
301 |
|
302 | ### process
|
303 |
|
304 | Zips and Uploads lambda functions in the configuration object.
|
305 | If the source of the function
|
306 | is already zipped and uploaded, it skips the step only updates the
|
307 | lambda config object.
|
308 |
|
309 | If the lambda config includes a link to zip file on S3, it skips
|
310 | the whole step.
|
311 |
|
312 | Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** returns the promise of updated configuration object
|
313 |
|
314 | ### updateSingleLambda
|
315 |
|
316 | Uploads the zip code of a single lambda function to AWS Lambda
|
317 |
|
318 | **Parameters**
|
319 |
|
320 | - `name` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** name of the lambda function
|
321 |
|
322 | Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** returns AWS response for lambda code update operation
|
323 |
|
324 | ## localRun
|
325 |
|
326 | A simple helper for running a function if `local` is passed as argument
|
327 |
|
328 | **Parameters**
|
329 |
|
330 | - `func` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** A javascript function
|
331 |
|
332 | **Examples**
|
333 |
|
334 | ```javascript
|
335 | // test.js
|
336 | const { localRun } = require('kes');
|
337 | localRun(() => {
|
338 | console.log('my function');
|
339 | });
|
340 | // result
|
341 | // $ node test.js local
|
342 | // my function
|
343 | ```
|
344 |
|
345 | Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** returns the result of the function call
|
346 |
|
347 | ## zip
|
348 |
|
349 | Zips a list of files or directories
|
350 |
|
351 | **Parameters**
|
352 |
|
353 | - `zipFile` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** filename and path where the zip file is stored
|
354 | - `srcList` **[array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** array of files and directories paths
|
355 | - `dstPath` **type** for directories whether to put the directories at
|
356 | root of the zip file or relative to your path on the local machine
|
357 |
|
358 | Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)**
|
359 |
|
360 | ## exec
|
361 |
|
362 | Executes shell commands synchronously and logs the
|
363 | stdout to console.
|
364 |
|
365 | **Parameters**
|
366 |
|
367 | - `cmd` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Bash command
|
368 | - `verbose` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** whether to post stdout to console (optional, default `true`)
|
369 |
|
370 | Returns **[Buffer](https://nodejs.org/api/buffer.html)** The command's stdout in for of Buffer
|
371 |
|
372 | ## configureAws
|
373 |
|
374 | Updates region of an AWS configuration and point to the correct
|
375 | of profile on ~/.aws/credentials file if necessary
|
376 |
|
377 | **Parameters**
|
378 |
|
379 | - `region` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** AWS region (optional, default `'us-east-1'`)
|
380 | - `profile` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** aws credentials profile name (optional, default `null`)
|
381 | - `role`
|
382 |
|
383 | ## fileToString
|
384 |
|
385 | Checks if the input is a file, if it is a file,
|
386 | it reads it and return the content, otherwise just pass
|
387 | the input as an output
|
388 |
|
389 | **Parameters**
|
390 |
|
391 | - `file` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** A file path or a string
|
392 |
|
393 | Returns **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** String content of a given file
|
394 |
|
395 | ## mergeYamls
|
396 |
|
397 | Merges two yaml files. The merge is done using lodash.merge
|
398 | and it happens recursively. Meaning that values of file2 will
|
399 | replace values of file 1 if they have the same key.
|
400 |
|
401 | **Parameters**
|
402 |
|
403 | - `file1` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Yaml path to file 1 or file 1 string
|
404 | - `file2` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Yaml path to file 2 or file 2 string
|
405 |
|
406 | Returns **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Merged Yaml file in string format
|
407 |
|
408 | ## determineKesClass
|
409 |
|
410 | Based on the information passed from the CLI by the commander
|
411 | module this function determines whether to use the default Kes class
|
412 | or use the override class provided by the user
|
413 |
|
414 | **Parameters**
|
415 |
|
416 | - `options` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** The options passed by the commander library
|
417 | - `Kes` **Class** the default kes class
|
418 |
|
419 | Returns **Class** Kes class
|
420 |
|
421 | ## failure
|
422 |
|
423 | In case of error logs the error and exit with error 1
|
424 |
|
425 | **Parameters**
|
426 |
|
427 | - `e` **[Error](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error)** error object
|
428 |
|
429 | ## success
|
430 |
|
431 | Exists the process when called
|
432 |
|
433 | ## getSystemBucket
|
434 |
|
435 | Discover and returns the system bucket used for deployment
|
436 |
|
437 | **Parameters**
|
438 |
|
439 | - `config` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** cumulus config object
|
440 |
|
441 | Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** name of the bucket
|