stratosphere - CloudFormation Template Generator
Type-safe CloudFormation template generation library for Rust.
Stratosphere provides a type-safe way to generate AWS CloudFormation templates in Rust, with compile-time validation of resource types and properties.
Getting Started
Install stratosphere with the AWS services you need:
Then build your CloudFormation template:
use *;
use ec2;
// Build your CloudFormation template using the generated resource macros
let template = build;
// Convert to JSON for use with CloudFormation APIs
let json = to_string_pretty.unwrap;
// This JSON can now be used with AWS CloudFormation APIs
Cargo Features
Each AWS service has its own feature flag (e.g., aws_ec2, aws_s3, aws_lambda).
Enable only the services you need for significant compile time savings:
Compile-Time Safety
Missing a required field is a compile-time error:
use ec2;
SecurityGroup!
Type mismatches between ExpString and ExpBool fields are caught by the compiler:
use ec2;
SecurityGroup!
Features
- Comprehensive coverage: Supports all AWS CloudFormation resource types
- Type-safe resource definitions: Pre-generated types for all AWS CloudFormation resources
- Compile-time validation: Catch errors before deployment
- Feature-gated services: Only compile the services you need, keeping build times fast
- CloudFormation intrinsic functions: Type-safe wrappers for
Fn::Sub,Fn::Join,Ref, etc. - Template builder API: Fluent interface for constructing templates
- Helper macros: Convenient macros for parameters, outputs, and common patterns
Why Stratosphere?
vs. writing JSON/YAML by hand: No more typos in resource type names, missing required properties, or type mismatches discovered at deploy time. Stratosphere catches these at compile time.
vs. AWS CDK / Pulumi: These don't support Rust. If your infrastructure tooling is already in Rust, stratosphere keeps everything in one language with one build system. It also generates plain CloudFormation JSON with no runtime dependencies or state backends.
vs. troposphere (Python): Similar approach (generate CloudFormation from code), but troposphere validates at runtime. Stratosphere validates at compile time.
vs. other Rust CloudFormation crates: Stratosphere auto-generates types from the official
AWS CloudFormation resource specification, covering all ~260 services. Alternatives either
cover a handful of hand-written services or are abandoned. Stratosphere is also the only
Rust crate with compile-time typed CloudFormation expressions (Ref, Fn::Sub, Fn::Join, etc.).
Stratosphere is a Rust re-implementation of the Haskell stratosphere library, which has been in production use since 2017.
Design Philosophy
Stratosphere provides pre-generated CloudFormation resource types gated behind Cargo features. Enable only the AWS services you need, and your compiled binary will only include those types.
This approach ensures fast compilation times and minimal binary size - you only pay for what you use.
Note: Once Rust's declarative macros 2.0 are stabilized, pre-generation can be removed in favor of on-demand type generation via proc macros with proper namespacing support.
Module Organization
services: Pre-generated CloudFormation resource types organized by vendor and servicetemplate: Core template types and builder APIvalue: CloudFormation values and intrinsic functionsresource_specification: AWS resource type definitions