cfn makes the following Cloud Formation tasks simpler.
- 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.
- Monitors stack progress, logging events.
- Returns a Promises. Resolves when stack Create / Update is done, Rejects if there is an error.
- Use regex pattern to delete stacks.
- Include
daysOld
to delete stacks this old.
$ npm install cfn --save-dev
Use cfn to create or update a Cloud Formation stack. It returns a promise. You can use Node.js modules or standard json for Cloud Formation 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');
Delete a stack.
// Delete the Foo-Bar stack
cfn.delete('Foo-Bar');
Cleanup stacks based on regex and daysOld.
// Delete stacks starting with TEST- that are 3 days old or more
cfn.cleanup({
regex: /TEST-/,
minutesOld: 60
})
.then(function() {
console.log('done')
});
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
}
})
Creates or Updates a stack if it already exists. Logs events and returns a Promise.
The name of the stack to Create / Update. If the first arg is a string it is used as name.
Options object. If the first arg is an object it will be used as options.
Path to the template (js or json file). 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.
Name of stack
Path to template (json or js file). If the optional second argument is passed in it will override this.
If set to true create and update runs asynchronously. Defaults to false.
This is an object that gets passed to function templates. For example this .js template
module.exports = function (params) {
return {
AWSTemplateFormatVersion: '2010-09-09',
Description: 'Test Stack',
Resources: {
testTable: {
Type: 'AWS::DynamoDB::Table',
Properties: {
...
TableName: 'FOO-TABLE-' + params.env
}
}
}
};
};
Could be deployed as follows
cfn({
name: 'Test-Stack',
template: 'template.js',
params: { env: 'dev' }
});
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');
});