Socket
Book a DemoInstallSign in
Socket

cf-options-builder

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cf-options-builder

Build and modify CloudFormation options objects

1.0.1
latest
npmnpm
Version published
Maintainers
1
Created
Source

cf-options-builder

Codeship Status for CondeNast/cf-options-builder Code Climate

This is a builder for CloudFormation options objects, which get passed to calls to the createStack method of the official AWS CloudFormation api client. This handles all the complexity surrounding Parameter lists, as well as adding and removing Capabilities and setting standard properties.

For example:

var AWS = require('aws');
var Builder = require('cf-options-builder');

var options = new Builder({
  Parameters: [
    { ParameterKey: 'InstancesDesiredCapacity', ParameterValue: 2 }
  ],
  TemplateUrl: 'https://c3.amazonaws.com/some-cloudformation-templates/my-template.json'
});

options
  .set('StackName', 'my-stack-name')
  .setParameter('Environment', 'staging')
  .setParameter('InstanceType', 't3.medium')
  .setParameter('InstancesDesiredCapacity', 3)
  .setCapability('CAPABILITY_IAM')
;

// Here's what it looks like...
console.log(options.value());
/*
{
  Parameters: [
    {
      ParameterKey: 'Environment',
      ParameterValue: 'staging'
    },
    {
      ParameterKey: 'InstanceType',
      ParameterValue: 't3.medium'
    },
    {
      ParameterKey: 'InstancesDesiredCapacity',
      ParameterValue: 3
    }
  ],
  TemplateUrl: 'https://c3.amazonaws.com/some-cloudformation-templates/my-template.json',
  StackName: 'my-stack-name',
  Capabilities: [
    'CAPABILITY_IAM'
  ]
}
*/

// ...and this is how you use it with AWS
AWS.config.credentials = new AWS.SharedIniFileCredentials({ profile: 'my-profile' });

var cloudformation = new AWS.CloudFormation();

cloudformation.createStack(options.value(), function(err) {
  if (err) {
    throw err;
  }
});

Keep in mind that Parameters are specific to your CloudFormation template! The Parameters used in this example are plausible but your template may not have them!

API

var options = new OptionsBuilder(baseOptions);

Creates a new OptionsBuilder. Can optionally take in a base options object as a starting place for modification. Defaults to an empty object. Stores internally as a deep clone so that calls on the OptionsBuilder don't munge the original object.

options.value()

Returns a usable CloudFormation options object. Clones the internal state of the OptionsBuilder so that further calls to the OptionsBuilder don't munge the object.

options.set(key, value)

Sets a key on the object.

options.remove(key)

Sets a key on the object to undefined.

options.setCapability(value)

Adds the specified capability if not already set.

options.removeCapability(value)

Removes the specified capability if set.

options.setParameter(key, value)

Sets the parameter with 'key' to have 'value'. Takes care to modify any parameter with the existing key instead of blindly appending to the end.

options.removeParameter(key)

Removes the parameter with 'key', if it exists.

Tests

Tests use mocha. You can run them with:

$ npm test

License

MIT/X11.

Keywords

AWS

FAQs

Package last updated on 13 Feb 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.