Ready to take your JavaScript development to the next level? Meet npm Enterprise - the ultimate in enterprise JavaScript.Learn more »


0.2.8 • Public • Published


Package, reuse and share particles for CloudFormation projects


Build Status Code Climate Coverage Status Dependency Status


Condensation is a gulp task generator that helps compile, package and upload AWS CloudFormation templates and supporting assets.

Any file with the extension .hbs will be compiled with Handlebars.js to support partials, helpers and variable replacement.


  • Write reusable CloudFormation snippits that can be included as partials
  • Package and upload templates and assets to multiple buckets across regions with one command.
  • References other templates within a distribution with AWS::CloudFormation::Stack and the templateS3Url helper
  • Upload scripts, configuration files and other assets alongside CloudFormation templates.
  • Use particles from other condensation compatible projects.


CloudFormation templates are great for creating, updating and deleting AWS resources. Reusing parts of templates, referencing other templates with AWS::CloudFormation::Stack and deploying cloud-init scripts can be difficult to manage.

  • Often sections such as AMI mappings are re-used by many templates. Handlebars partials provide a way to write the mapping once and reuse it without copying from template to template.
  • It is common to set up resources, such as a VPC, with nearly identical attributes and structure for different applications and services. Condensation allows that definition to become a independent stack that can be referenced by other templates that are part of the same package.
  • To bootstrap instances it is beneficial to have scripts and configuration files deployed in a known location and verisoned with the template they are associated with.
  • When using AWS::CloudFormation::Authentication to download assets from S3 buckets all resources must be in the same region. Condensation makes it easy to deploy the same templates and assets to multiple regions and ensure the referencing URLs are correct.

Stacks (templates) can be deployed to a bucket where each stack is able to reference one another. That pattern can repeated using difference confgurations for the same templates to support development, production and multi-region buckets.


"TemplateURL": "{{{templateS3Url 'vpc.template' }}}"
"TemplateURL": "{{{templateS3Url 'subnet.template' }}}"


"TemplateURL": "<BUCKET>/cftemplates/vpc.template"
"TemplateURL": "<BUCKET>/cftemplates/subnet.template"

With the help of Handlebars the URL will always reference a template deployed within the same bucket.


Quick Start Examples: condensation-examples

Create a project

> npm init

Recommended .gitignore


Install gulp

> npm install -g gulp

Install condensation

> npm install condensation --save

Add condensation to gulpfile.js

var gulp = require('gulp');

var config = {
  s3: [
      aws: {
        region: 'us-east-1',
        bucket: 'MY-FAVORITE-BUCKET',
      validate: true,
      create: true
  dist: 'dist'

// Add necessary gulp tasks to build, compile and validate
// CloudFormation templates

Project Structure

-- guplfile.js
  -- cftemplates
  -- helpers
  -- partials

Condensation loads particles through core helper methods. The core helper methods are able to load particles from the local project as well as any condensation compatible project added as a npm dependency.

All helpers follow the same pattern:


Lazy Loading

Particles will only be included in the final distribution if they are referenced from a hbs file.


Files to be uploaded to S3 that are used to supplement CloudFormation templates. Files can include boostrap scripts, packaged install files or configuration files.

Any file with a .hbs extension will be compiled with handlebars and saved to S3 without the .hbs extension.

Asset URLs can be built with the assetS3Url helper:

{{{assetS3Url 'my-asset'}}}

{{{assetS3Url 'module:<MODULE>' 'module-asset'}}}

Example Output:



To include assets that are not directly referenced from a template use the requireAssets helper. It will ensure a glob of assets are included in the distribution.

{{{requireAssets '/**'}}

{{{requireAssets 'module:<MODULE>' '/**'}}}


CloudFormation templates that will be uploaded to S3.

Any file with a .hbs extension will be compiled with handlebars and saved to S3 without the .hbs extension.

Template URLs can be built with the assetS3Url helper:

{{{templateS3Url 'my.template'}}}

{{{templateS3Url 'module:<MODULE>' 'module.template'}}}

Example Output:




Contents of files here will be loaded as partials that can be used in assets and cftemplates.

These files will not be packaged or uploaded to S3.

Partils can be loaded with the partial helper:

{{{partial 'my-partial'}}}

{{{partial 'module' 'module-partial'}}}


Node modules that export a function that is built as a Handlebars block helper.

Helpers are called with the helper helper:

{{{helper 'my-helper'}}}

{{{helper 'module:<MODULE>' 'module-helper'}}}


Get a full list of tasks by running gulp -T

By default all tasks are prefixed with condensation:. This can be changed with the taskPrefix config option.


The default task is an alias for build. It will prepare all files for deployment to s3. Templates and assets are written to the configured dist directory.

> gulp condensation:default


Will list all the configured s3 bukets and module corresponding ID.

> gulp condensation:s3:list
[10:21:47] Using gulpfile ~/condensation-example/gulpfile.js
[10:21:47] Starting 'condensation:s3:list'...
[10:21:47] Finished 'condensation:s3:list' after 153 μs

The IDs can be used to deploy to a single bucket instead of all buckets.


For the deploy task to run AWS credentials must be set as environment variables: AWS_SECRET_ACCESS_KEY and AWS_ACCESS_KEY_ID


This will upload templates to all cofigured S3 buckets.


Deploy tempates to a specific S3 bucket.


Deploy tempates to all S3 buckets that contain the label, LABEL.

Config Options

var config = {
  // Array of S3 buckets to deploy to
  s3: [
      // AWS specific options
      aws: {
        region: 'us-east-1',
        bucket: '',

      // Run CloudFormation validation during the build task for this bucket
      validate: true,

      // Create this bucket if it does not already exist
      create: true

      // Prefix all objects (allows for multiple deploymets to the same bucket
      prefix: '',

      labels: ['east']
  // The prefix to add to all generated gulp tasks (default: 'condensation')
  // An empty string will remove the prefix
  //     - condensation:deploy will become deploy
  taskPrefix: '',

  // Directory that contains the `particles` directory.
  // Used for test scripts, should not be changed if sharing templates
  root: './',

  // Where the build task will put the distribution
  dist: 'dist'

Front Matter

All cftemplates and partials are first processed with gray-matter to load any default data definitions.


Errors due to badly formed JSON or failed CF validations will stop the process and the offendng files will be dumped to condensation_error


npm i condensation

Downloadsweekly downloads









last publish


  • avatar
Report a vulnerability