npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

upbeat-cloudformation-json-stitcher

v1.0.10

Published

This utility combines JSON Cloudformation resource templates stored in individual files into a single template file.

Downloads

94

Readme

Upbeat CloudFormation JSON Stitcher

This utility scans the supplied directory for JSON files and builds a CloudFormation template with the logic described below.

Usage

The following command will combine all files in the current directory into a template.json file also included in the current directory (not recommended).

node index.js

The following command will combine all files in the current directory into an output file at the specified location with the specified name.

node index.js --output-path "../some-other-directory" --filename "my-template.json"

The following command will combine all files in the specified directory into an output file at the specified location with the specified name.

node index.js --source "../some-other-location/cloud-formation/regional/templates" --output-path ".." --filename "my-template.json"

The following command will combine files with paths that do not match the ":::" delimited regular expressions in the exclude list. This can be helpful if you only want to test certain resources in your stack.

node index.js --exclude "elastic-beanstalk:::rds:::Portal\\(?!Develop\\)" //this skips any files with elastic-beanstalk, rds, or Portal in their paths, with the exception of PortalDevelop, which would be included via the negative lookahead in the regex

The following command will include template version and description attributes on the generated template.

node index.js --format-version "2010-09-09" --description "my description here"

The following command will automatically bump a semver version at the specified JSON path with each stitch (we use this in concert with a "donothing" custom lambda resource to trigger builds in parent and all nested stacks when there's an update".

node index.js --semver "MyCustomResource.Properties.Version"

Note that the above mutates the source file before copying the template fragment to the output file.

For usage in a parent package, we'll typically add a script like that below to the package.json.

"scripts": {
    "stitch-regional-infrastructure": "node node_modules/upbeat-cloudformation-json-stitcher/index.js --description "Our Regional Infrastructure" --semver "Semver.Properties.Version" --source regional/templates --output-path regional/build --filename lower.template.json --exclude Portal\\(?!Develop\\):::SomeOtherFragmentToExclude.json"
    ...
}

Configuration Mapping

Filenames that are found in the following list extend the like-named top level attributes in the template:

Metadata.json
Parameters.json
Rules.json
Mappings.json
Conditions.json
Transform.json
Outputs.json

If multiple files for a given attribute are discovered in the recursive directory scan (e.g., multiple Parameters.json files), these will be combined into the final object output in the template.

The following attributes are populated only if specified in the supplied arguments:

AWSTemplateFormatVersion
Description

See examples above for reference.

Resource Mapping

The filename (sans .json extension) is used as the resource name in the constructed template. (e.g., MyS3Bucket.json is mapped to Template.Resources.MyS3Bucket in the generated JSON template) For example, the following directory structure would generate the output below.

- s3
  -- MyS3Bucket.json
- r53
  -- domains
    --- MyR53Record.json

Inputs

MyS3Bucket.json

{
  "Type": "AWS::S3::Bucket",
  "Properties": {
    "AccessControl": "Private",
    "BucketName": {
      "Fn::Sub": "upbeat-elastic-beanstalk-${AWS::Region}-${Stage}"
    },
    "OwnershipControls": {
      "Rules": [
        {
          "ObjectOwnership": "BucketOwnerEnforced"
        }
      ]
    }
  }
}

MyR53Record.json

{
  "Type": "AWS::Route53::RecordSet",
  "Properties": {
    "HostedZoneId": "some-zone-id",
    "Name": "some-source-url.com",
    "Type": "CNAME",
    "TTL": "60",
    "ResourceRecords": [
      "some-destination-url.com"
    ]
  }
}

Output

{
	"Resources": {
		MyS3Bucket: {
		  "Type": "AWS::S3::Bucket",
		  "Properties": {
		    "AccessControl": "Private",
		    "BucketName": {
		      "Fn::Sub": "upbeat-elastic-beanstalk-${AWS::Region}-${Stage}"
		    },
		    "OwnershipControls": {
		      "Rules": [
		        {
		          "ObjectOwnership": "BucketOwnerEnforced"
		        }
		      ]
		    }
		  }			
		}
		MyR53Record: {
		  "Type": "AWS::Route53::RecordSet",
		  "Properties": {
		    "HostedZoneId": "some-zone-id",
		    "Name": "some-source-url.com",
		    "Type": "CNAME",
		    "TTL": "60",
		    "ResourceRecords": [
		      "some-destination-url.com"
		    ]
		  }
		}
	}
}