Skip to content
/ cfn Public
forked from josmo/cfn

Simple Cloud Formation for Node.js

License

Notifications You must be signed in to change notification settings

sbasir/cfn

 
 

Repository files navigation

cfn

cfn makes the following AWS CloudFormation tasks simpler.

Create / Update Stack
  • If the stack already exists, it Updates; otherwise, it Creates.
  • Monitors stack progress, logging events.
  • Returns a Promises. Resolves when stack Create / Update is done, Rejects if there is an error.
Delete Stack
  • Monitors stack progress, logging events.
  • Returns a Promises. Resolves when stack Create / Update is done, Rejects if there is an error.
Validate Templates
  • Checks if a template is valid
  • Returns a Promises. Resolves when template is valid, Rejects if there is an error.

Install

$ npm install cfn --save-dev

Usage

Create / Update

Use cfn to create or update an AWS CloudFormation stack. It returns a promise. You can use Node.js modules or standard json or yaml for AWS CloudFormation templates.

var cfn = require('cfn');


// Create or update (if it exists) the Foo-Bar stack with the template.js Node.js module.
cfn('Foo-Bar', __dirname + '/template.js')
    .then(function() {
        console.log('done');
    });

// Create or update the Foo-Bar stack with the template.json json template.
cfn('Foo-Bar', 'template.json');

// Create or update the Foo-Bar2 stack with the template.yml yaml template.
cfn('Foo-Bar2', 'template.yml');

Delete

Delete a stack.

// Delete the Foo-Bar stack
cfn.delete('Foo-Bar');

Stack Exists

Returns a boolean if a stack exists or not

// Returns boolean if stack name 'foo-bar' exists
cfn.stackExists('foo-bar')
    .then(function(exists){
        if (exists){
            //Do something
        }
    })

Validate

Checks if a template is valid

// Validate a template.js Node.js module.
cfn({
    template: __dirname + '/template.js',
    params: {
        foo: 'bar'
    },
    awsConfig: {
        region: 'us-west-2'
    }
}).validate()
    .then(function(data){
        //Stack is valid do something
    },
    function(err){
        //Stack is invalid
    })

// Validate a json template.
cfn.validate('us-west-2', 'template.json');

// Validate a yaml template.
cfn.validate('us-west-2', 'template.yml');

API

cfn(name|options[, template])

Creates or Updates a stack if it already exists. Logs events and returns a Promise.

name

The name of the stack to Create / Update. If the first arg is a string it is used as name.

options

Options object. If the first arg is an object it will be used as options.

template

Path to template (yaml or json file), JSON object, serialized JSON string, YAML string, or a S3 Bucket URL. This is optional and if given will override options.template (if present). This arg is helpful if the first arg is the name of the template rather than an options object.

options.name

Name of stack.

options.template

Path to template (json, yaml or js file), JSON object, serialized JSON string, or a YAML string. If the optional second argument is passed in it will override this.

options.cfParams

The standard AWS CloudFormation parameters to be passed into the template.

A standard AWS CloudFormation template in yaml format is shown below:

AWSTemplateFormatVersion: '2010-09-09'
Description: 'Test Stack'

Parameters:
  env:
    Type: String
    Description: The environment for the application

Resources:
  testTable:
    Type: AWS::DynamoDB::Table
    Properties:
      ...
      TableName: !Sub FOO-TABLE-${env}

Is deployed as follows:

cfn({
    name: 'Test-Stack',
    template: 'template.yml',
    cfParams: { env: 'dev' }
});
options.awsConfig

This allows you to pass any config properties allowed by the AWS Node.js SDK

cfn({
    name: 'Foo-Bar',
    template: _dirname + '/template.js',
    awsConfig: {
        region: 'us-west-2'
        accessKeyId: 'akid',
        secretAccessKey: 'secret'
    }
}).then(function() {
    console.log('done');
});

repo tagging

update package.json version git commit -m"update version" git push git tag -a v1.5.10 # git tag -f v1.5.10 to overwrite tag to new commit git push origin --tags

About

Simple Cloud Formation for Node.js

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 63.4%
  • TypeScript 36.6%