<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

### Table of Contents

-   [Config](#config)
    -   [parse](#parse)
-   [Kes](#kes)
    -   [updateSingleLambda](#updatesinglelambda)
    -   [compileCF](#compilecf)
    -   [uploadToS3](#uploadtos3)
    -   [uploadCF](#uploadcf)
    -   [cloudFormation](#cloudformation)
    -   [validateTemplate](#validatetemplate)
    -   [describeCF](#describecf)
    -   [opsStack](#opsstack)
    -   [createStack](#createstack)
    -   [updateStack](#updatestack)
-   [Lambda](#lambda)
    -   [updateLambda](#updatelambda)
    -   [zipLambda](#ziplambda)
    -   [uploadLambda](#uploadlambda)
    -   [zipAndUploadLambda](#zipanduploadlambda)
    -   [process](#process)
    -   [updateSingleLambda](#updatesinglelambda-1)
-   [localRun](#localrun)
-   [exec](#exec)
-   [configureAws](#configureaws)

## Config

This class handles reading and parsing configuration files.
It primarily reads `stage.yml`, `config.yml` and `.env` files

**Parameters**

-   `stack` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Stack name
-   `stage` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Stage name
-   `configFile` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** path to the config.yml file
-   `stageFile` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** path to the stage.yml file (optional)
-   `envFile` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** path to the .env file (optional)

**Examples**

```javascript
const configurator = new Config('mystack', 'dev', '.kes/config.yml', '.kes/stage.yml', '.kes/.env');
const config = configurator.parse();
```

### parse

Main method of the class. It parses a configuration and returns it
as a JS object.

**Examples**

```javascript
const configInstance = new Config(null, null, 'path/to/config.yml', 'path/to/stage.yml', 'path/to/.env');
config = configInstance.parse();
```

Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** the configuration object

## Kes

The main Kes class. This class is used in the command module to create
the CLI interface for kes. This class can be extended in order to override
and modify the behaviour of kes cli.

**Parameters**

-   `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** a js object that includes required options.
    -   `options.stack` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** the stack name (required)
    -   `options.stage` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** the stage name (optional, default `'dev'`)
    -   `options.region` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** the aws region (optional, default `'us-east-1'`)
    -   `options.profile` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** the profile name (optional, default `null`)
    -   `options.kesFolder` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** the path to the kes folder (optional, default `'.kes'`)
    -   `options.configFile` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** the path to the config.yml (optional, default `'config.yml'`)
    -   `options.stageFile` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** the path to the stage.yml (optional, default `'stage.yml'`)
    -   `options.envFile` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** the path to the .env file (optional, default `'.env'`)
    -   `options.cfFile` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** the path to the CF template (optional, default `'cloudformation.template.yml'`)

**Examples**

```javascript
const { Kes } = require('kes');

const options = { stack: 'myStack' };
const kes = new Kes(options);

// create a new stack
kes.createStack()
 .then(() => updateStack())
 .then(() => describeCF())
 .then(() => updateSingleLambda('myLambda'))
 .catch(e => console.log(e));
```

### updateSingleLambda

Updates code of a deployed lambda function

**Parameters**

-   `name` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** the name of the lambda function defined in config.yml

Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** returns the promise of an AWS response object

### compileCF

Compiles a CloudFormation template in Yaml format.

Reads the configuration yaml from `.kes/config.yml`.

Writes the template to `.kes/cloudformation.yml`.

Uses `.kes/cloudformation.template.yml` as the base template
for generating the final CF template.

Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** returns the promise of an AWS response object

### uploadToS3

This is just a wrapper around AWS s3.upload method.
It uploads a given string to a S3 object.

**Parameters**

-   `bucket` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** the s3 bucket name
-   `key` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** the path and name of the object
-   `body` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** the content of the object

Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** returns the promise of an AWS response object

### uploadCF

Uploads the Cloud Formation template to a given S3 location

Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** returns the promise of an AWS response object

### cloudFormation

Calls CloudFormation's update-stack or create-stack methods

**Parameters**

-   `op` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** possible values are 'create' and 'update'

Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** returns the promise of an AWS response object

### validateTemplate

Validates the CF template

Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** returns the promise of an AWS response object

### describeCF

Describes the cloudformation stack deployed

Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** returns the promise of an AWS response object

### opsStack

Generic create/update  method for CloudFormation

**Parameters**

-   `ops`  
-   `op` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** possible values are 'create' and 'update'

Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** returns the promise of an AWS response object

### createStack

Creates a CloudFormation stack for the class instance

Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** returns the promise of an AWS response object

### updateStack

Updates an existing CloudFormation stack for the class instance

Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** returns the promise of an AWS response object

## Lambda

Copy, zip and upload lambda functions to S3

**Parameters**

-   `config` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** the configuration object
-   `kesFolder` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** the path to the `.kes` folder
-   `bucket` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** the S3 bucket name
-   `key` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** the main folder to store the data in the bucket (stack + stage)

### updateLambda

Updates the lambda object with the bucket, s3 zip file path and
local zip file location

**Parameters**

-   `lambda` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** the lambda object

Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** returns the updated lambda object

### zipLambda

Copy source code of a given lambda function, zips it, calculate
the hash of the source code and updates the lambda object with
the hash, local and remote locations of the code

**Parameters**

-   `lambda` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** the lambda object

Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** returns the updated lambda object

### uploadLambda

Uploads the zipped lambda code to a given s3 bucket
if the zip file already exists on S3 it skips the upload

**Parameters**

-   `lambda` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** the lambda object. It must have the following properties
    -   `lambda.bucket` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** the s3 buckt name
    -   `lambda.remote` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** the lambda code's key (path and filename) on s3
    -   `lambda.local` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** the zip files location on local machine

Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** returns the promise of updated lambda object

### zipAndUploadLambda

Zips and Uploads a lambda function. If the source of the function
is already zipped and uploaded, it skips the step only updates the
lambda config object.

If the lambda config includes a link to zip file on S3, it skips
the whole step.

**Parameters**

-   `lambda` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** the lambda object.

Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** returns the promise of updated lambda object

### process

Zips and Uploads lambda functions in the congifuration object.
If the source of the function
is already zipped and uploaded, it skips the step only updates the
lambda config object.

If the lambda config includes a link to zip file on S3, it skips
the whole step.

Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** returns the promise of updated configuration object

### updateSingleLambda

Uploads the zip code of a single lambda function to AWS Lambda

**Parameters**

-   `name` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** name of the lambda function

Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** returns AWS response for lambda code update operation

## localRun

A simple helper for running a function if `local` is passed as argument

**Parameters**

-   `func` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** A javascript function

**Examples**

```javascript
// test.js
const { localRun } = require('kes');
localRun(() => {
  console.log('my function');
});
// result
// $ node test.js local
// my function
```

Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** returns the result of the function call

## exec

Executes shell commands synchronously and logs the
stdout to console.

**Parameters**

-   `cmd` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Bash command
-   `verbose` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** whether to post stdout to console (optional, default `true`)

Returns **[Buffer](https://nodejs.org/api/buffer.html)** The command's stdout in for of Buffer

## configureAws

Updates region of an AWS configuration and point to the correct
of profile on ~/.aws/credentials file if necessary

**Parameters**

-   `region` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** AWS region (optional, default `'us-east-1'`)
-   `profile` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** aws credentials profile name (optional, default `null`)
-   `role`   (optional, default `null`)
