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

@hexlabs/cloudformation-ts

v3.0.288

Published

A Typescript way to build CloudFormation

Downloads

206

Readme

CcloudFormation-ts workflow NPM Version

HexLabs CloudFormation.ts

CloudFormation-ts is a one-to-one mapping of Amazon's CloudFormation generated into a TypeScript library allowing users to write type safe stacks in TypeScript.

CloudFormation can be invoked inside a Typescript program or on command line by running

npm install -g @hexlabs/cloudformation-ts

Benefits Include

  • Type Safety
  • Code Completion
  • Stacks as Code
  • Modular Templating
  • Coverage generated for all Cloudformation resources with each release

This is what it looks like

const template = await AwsLoader.register('s3', 'sns').load();

export default template.create().build(aws => {
  const snsTopic = aws.sns.topic();
  const bucket = aws.s3.bucket({
    bucketName: snsTopic.attributes.TopicName
  });
})

This is what it Produces

{
  "Parameters": {},
  "Resources": {
    "Topic": {
      "Type": "AWS::SNS::Topic"
    },
    "Bucket": {
      "Type": "AWS::S3::Bucket",
      "Properties": {
        "BucketName": {
          "Fn::GetAtt": [
            "Topic",
            "TopicName"
          ]
        }
      }
    }
  }
}

Get Started

To install on command line globally use

npm install -g @hexlabs/cloudformation-ts

Full list of commands

try running: npx @hexlabs/cloudformation-ts
translate [options] <templateLocation>
deploy [options] <stackName> <templateLocation> [fileLocation]
delete [options] <stackName>
help [command]                                   

Translate

Translate a template written in TypeScript into a JSON CloudFormation template.

This step is optional, the deploy step will also accept a .ts file or .json file.

translate [options] <templateLocation>

Options:
  -r, --region <region>         The region to gather stack outputs from (default: "eu-west-1")
  -t, --ts-project <fileName>   TS Config
  -h, --help                    display help for command

Deploy

Deploy a template to AWS. templateLocation can be a .ts or .json file. If .json then jsonFileLocation is not required.

Usage: cfts deploy [options] <stackName> <templateLocation> [jsonFileLocation]

Options:
  -r, --region <region>               The region to delete stack from (default: "eu-west-1")
  -e, --endpoint-url <endpoint-url>
  -c, --capabilities <capability...>  A space separated list of any of CAPABILITY_IAM, CAPABILITY_NAMED_IAM or CAPABILITY_AUTO_EXPAND (default: ["CAPABILITY_NAMED_IAM"])
  -f, --file <files...>               A space separated list of files to upload to s3 (the first location will be injected as CodeBucket, CodeLocation parameters for use in lambda),
  -b, --bucket <bucket>               The s3 bucket in which to upload files
  -x, --bucket-region <region>        The s3 bucket region in which to upload files
  -p, --prefix <prefix>               The s3 object key prefix in which to upload files
  --stack-upload                      Set if stack should be uploaded and referenced in s3 (Use for large stacks)
  -s, --stack-info <stacks...>        A space separated list of stacks to get outputs as environment variables
  -o, --output-file <fileName>        A file to output key-value pairs from stack-info
  -t, --ts-project <fileName>         TS Config
  -v, --parameters <parametersFile>   The location of the parameters file (default: "parameters.json")
  -h, --help                          display help for command

Getting outputs from other CloudFormation Stacks

When building infrastructure in AWS, a common need is to reference something else in your account.

To achieve this you need to return an Output in the referenced stack then when translating the referencing stack pass the name of the stack as one of the -s arguments.

Note: If you need an output from a stack in another region simply prefix the stack name with region:<<stack name>>

Here is a contrived example where we create bucket in us-east-1 and reference its ARN in eu-west-1.

Stack A (in us-east-1) Deployed as my-stack-a

const template = await AwsLoader.register('s3').load();
export default template.create().build(aws => {
  const bucket = aws.s3.bucket({
    bucketName: 'my-bucket-in-stack-a'
  });

  return {
    outputs: {
      'MyBucketInStackA': stackOutput(bucket.attributes.Arn)
    }
  }
})

Stack B (in eu-west-1)

const template = await AwsLoader.register('s3').load();
export default template
  .create("my-stack-b-template.json")
  .params({
    MyBucketInStackA: { type: 'String' }
  })
  .build((aws, params) => {
  aws.s3.bucket({
    bucketName: join(params.MyBucketInStackA(), '-contrived-example')
  });
})

stack-b-properties.json

{
  "MyBucketInStackA": {
    "envName": "MyBucketInStackA"
  }
}

Command to deploy:

npx  @hexlabs/cloudformation-ts translate my-stack-b-template.ts
npx @hexlabs/cloudformation-ts deploy -r eu-west-1 -s us-east-1:my-stack-a -- my-stack-b my-stack-b-template.json