Custom CloudFormation resource types
I recently had the opportunity to explore building custom CloudFormation resource types as a mechanism to support a stream-aligned team. It was intriguing to play with this new-to-me tool and see how it could reduce complexity for the team.
I’ve written before about using Step Functions to build custom resources in CloudFormation. This builds on the old-school custom resources mechanism where you provide a Lambda handler as part of your stack. This is convenient for very small or one-off duct-tape situations, but if you need more complex resource logic or if you want to provide a simple resource interface to a bunch of teams, there is a better way.
The AWS CloudFormation registry and the CloudFormation command-line interface are this better way. They allow you to write your own resource provider that will be exposed using the exact same mechanisms that CloudFormation uses for many AWS-provided resource types.
You can do all kinds of super-neat things with resource types, and there is a neat pattern to report progress when your resource may take a while to create or when there are multiple steps to create your resource.
Batteries not always included
Resource providers can expose configuration data; this is super-handy if you want to attach “account-level” configuration (really region-level configuration) to your type’s handler. Unfortunately, while an API exists to programmatically set the configuration data, tragically and ironically there is no CloudFormation support for setting the configuration data on a resource type.
Because of the super-cool open way that AWS CloudFormation resource providers are built, a person could theoretically open a pull request on the aws-cloudformation/aws-cloudformation-resource-providers-cloudformation repository, duplicating the
aws-cloudformation-hooktypeconfig
folder and refactoring it to implementAWS::CloudFormation::ResourceTypeConfig
, but I haven’t gone there yet. Probably should open a roadmap issue for discussion first.
I used an old-school custom resource to set the configuration for my custom types. 🤦♂️