cloudformation-resources
v1.7.0
Published
Typed CloudFormation resource names for safety and auto-completion
Downloads
157
Readme
CloudFormation Resource Identifiers
I was tired of passing string values as CDK resource type identifiers in my TypeScript projects, so I scraped AWS's docs and built a class-based typeset of (a handful of) identifiers.
We have a type system; we can do better. Except for the project name: that bit remains completely terrible.
Installation
npm
npm i --save-dev cloudformation-resources
Yarn
yarn add --dev cloudformation-resources
Usage
In your CDK TypeScript files:
import { Template } from "aws-cdk-lib/assertions";
import { AWS } from "cloudformation-resources";
const app = newApp("dev");
const stack = new VpcStack(app, "vpc-stack", {});
const template = Template.fromStack(stack);
template.resourceCountIs(AWS.EC2.VPC, 1); // instead of the wholly-gnarly "AWS::EC2::VPC"
Alternatively, you can import just the service set:
import { EC2 } from "cloudformation-resources/ec2";
const app = newApp("dev");
const stack = new VpcStack(app, "vpc-stack", {});
const template = Template.fromStack(stack);
template.resourceCountIs(EC2.VPC, 1);
Building Typesets
Building (or re-building) the identifier sets requires Deno. To scrape the AWS docs and generate the TypeScript files, run:
deno run --allow-net --allow-write --allow-read scripts/scrape-identifiers.ts
Contributing
Pull requests are welcome. To add services, add them to servicePages
in
scripts/scrape-identifiers.ts
, then run the build command.
[!IMPORTANT] Be sure to run
deno fmt
before committing to ensure consistent formatting.