Background

ocaml-cfgen uses CloudFormation Resource Definitions to generate OCaml types and Yojson serialisers in order to be able to generate CloudFormation templates.

It is supported by a internal library called Cf_base which contains the base template API, special serialisers for handling resource relationships (through token values), and auxilliary DSL APIs (like Cfgen.Helpers.Iam_policy for IAM policy generation).

Definitions

Concepts and definitions that appear in this documentation for CloudFormation and cfgen.

CloudFormation Concepts

cfgen Concepts

Templates

Cfgen.Template.t Template types represent a CloudFormation template under assembly.

Use the API functions in Cfgen.Template to add resources, parameters or outputs.

Constructs

Constructs are a higher level abstraction than CloudFormation resources. Borrowing from CDK terminology, we can define constructs through different levels of abstraction:

* L1 constructs are the generated CloudFormation resource types in Cfgen.BaseConstructs * L2 constructs are higher-level than L1 resources, usually centered on a primary resource type (like Lambda functions or API Gateway instances), but with helper functions to generate the "glue" resources that surround them (like IAM roles, Lambda Event Source Mappings, Event Bridge rules, etc). An L2 construct will typically generate more than one underlying CloudFormation resource * L3 constructs implement patterns designed to implement common tasks. They will combine multiple L2 and L1 constructs to achieve a common goal, like deploying a Lambda function to respond to an EventBridge Rule with the correct level of failure handling (like DLQs) and monitoring (like CloudWatch alarms). They typically cross service boundaries for this reason.

cfgen only provides L1 constructs at this time. You can achieve L2 and L3 constructs through standard composition and abstraction mechanisms in OCaml, e.g. functions and modules, but cfgen does not provide any special support for working with them (yet).

Tokens

Tokens are special strings or numbers that are substituted with CloudFormation intrinsic functions at template serialisation. They permit access to dynamic values, such as resource attributes, account or region variables, or imported values from other stack exports, when constructing resource properties or template outputs.