Skip to content
This repository has been archived by the owner on Mar 4, 2023. It is now read-only.
/ aws-cf-monitor Public archive

A wrapper around the AWS CloudFormation Node API that monitors the progress of the CF commands while providing smart logging

Notifications You must be signed in to change notification settings

colbywhite/aws-cf-monitor

Repository files navigation

aws-cf-monitor

Build Status npm npm npm

A wrapper around the AWS CloudFormation Node API that monitors the progress of CF commands while providing smart logging.

The AWS API handles CloudFormation commands asynchronously, meaning you make a request to create a stack and you then write a bunch of boilerplate code to poll and wait for the creation to finish.

This aims to replace that boilerplate code with some pretty winston logging so you can watch the events as they come.

Installation

npm i -S aws-cf-monitor
npm i -S chalk winston aws-sdk  # install peer deps

Usage

const AWS = require('aws-sdk');
const {LOG_NAME, Monitor} = require('aws-cf-monitor');
const winston = require('winston');

const input = {StackName: name, TemplateBody: template};
const cf = new AWS.CloudFormation();

// simplest log configuration
winston.loggers.add(LOG_NAME, {
    format: winston.format.simple(),
    transports: [new winston.transports.Console()]
});

cf.createStack(input).promise()
    .then(() => new Monitor().monitor(name, cf))
    .then((status) => {
      console.log(`Hooray, the stack is ${status}`);
      console.log('And I didn\'t have to write a bunch of boilerplate to wait for it!');
    });

Delay Interval

As the CFMonitor waits for your stack to complete, it will poll for the status. The interval in between polls can be controlled via the AWS_CF_MONITOR_DELAY environment variable. The default is 5000 milliseconds.

Configure logger

You can configure the logger by whichever means you prefer to configure a winston logger. The name of the logger is aws-cf-monitor, which is a constant saved in LOG_NAME.

See the winston project for more information.

Inspiration

The way the [serverless framework](https://github.com/serverless/serverless) handles these CloudFormation requests is the inspiration. The framework handles polling well and prints some pretty color-coded logging as well, making it easy to follow the progress of the stack.

The bulk of that original logic is in the monitorStack.js.

About

A wrapper around the AWS CloudFormation Node API that monitors the progress of the CF commands while providing smart logging

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •