Library / SDK
cloudtools/troposphere avatar
cloudtools/troposphere

troposphere: Building AWS CloudFormation Templates in Python

troposphere - Python library to create AWS CloudFormation descriptions

4,944 stars1,406 forksPythonBSD-2-Clause

At a glance

What is it?
troposphere is a Python library that generates CloudFormation JSON or YAML from typed Python objects, with property and type checking built in. It suits teams that already keep infrastructure in Python and want validation before the template reaches AWS.
Who is it for?
Adopt troposphere if your infrastructure already lives in Python and you want CloudFormation errors raised at object construction rather than at stack creation. Skip it if you need a language-agnostic template format, a state file, or drift detection, since it emits templates and nothing more.
Can I use it commercially?
Yes. BSD-2-Clause is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository last received commits 9 days ago.
What is it written in?
Mainly Python, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on September 27, 2026, and from our analysis. They are not legal advice.

Editorial analysis

The gap troposphere fills between hand-written YAML and a full IaC framework

CloudFormation templates are JSON or YAML documents. Editing them by hand means a typo in a property name, an integer where a string belongs, or a missing required field surfaces only when the stack operation fails, which is slow and sometimes expensive. troposphere replaces the document with Python objects: you instantiate a class per resource, assign attributes, and call a serialization method. The library describes itself as allowing "easier creation of the AWS CloudFormation JSON by writing Python code to describe the AWS resources."

The audience is narrow and specific. If your team writes deployment scripts, configuration generators or internal tooling in Python, troposphere lets those programs produce templates directly, without a separate DSL and without leaving the language. If your infrastructure is already expressed in another tool and works, troposphere adds a translation layer you do not need. The README also notes basic support for OpenStack resources via Heat, so a shop running both AWS and OpenStack can keep one generation path.

How the Template object, resource classes and Ref fit together

The unit of work is a Template. Resources are added to it with add_resource(), which returns the object so it can be passed straight into Ref() for cross-resource references. The README shows this chaining directly: add_resource() on an EC2 instance returns the instance, and Ref(instance) wraps it.

Validation happens at two moments. Attribute assignment is checked as you write it: setting an attribute the resource does not define raises AttributeError, and setting a property with the wrong Python type raises TypeError naming the expected type. Required properties are checked when the template is serialized, not when the resource is constructed. The README's Subnet example is explicit about this: constructing ec2.Subnet with only VpcId succeeds, and the ValueError about the missing CidrBlock appears when to_json() is called.

That split matters for how you structure code. A builder function can assemble resources freely and fail late, or you can serialize early to force the check. Outputs, parameters and mappings are first-class objects too: add_parameter, add_mapping and add_output take Parameter, Output and plain dictionaries, and intrinsic functions such as Ref, GetAtt, FindInMap and Base64 are importable from the top-level package.

Installing troposphere and generating a first template

The README gives pip as the installation path. The base install pulls in cfn_flip, which requirements.txt lists as cfn_flip>=1.0.2 and describes as a library needed by setup.py. Run the plain install first:

bash
pip install troposphere

If you plan to use AWS policy objects, the README recommends the extra that pulls in awacs, a related library from the same organisation:

bash
pip install troposphere[policy]

The README also documents a source install for people who clone the repository, noting that sudo may be needed depending on the Python installation:

bash
python setup.py install

With the package installed, the smallest useful program builds a Template, adds one resource, and prints it. The README's own example uses an EC2 instance:

python
from troposphere import Template
import troposphere.ec2 as ec2

t = Template()
instance = ec2.Instance("myinstance", ImageId="ami-951945d0", InstanceType="t1.micro")
t.add_resource(instance)
print(t.to_json())

The output is a JSON document with a Resources key, the logical name myinstance, a Type of AWS::EC2::Instance and a Properties block holding the two attributes. Calling to_yaml() instead produces the same structure in YAML, which is what you would hand to the CloudFormation console or the AWS CLI. Note that the AMI and instance type in the README are the ones it ships with; substitute values valid for your account and region before creating a stack.

What the type checking does not catch

The checks are structural, not semantic. troposphere knows that ImageId expects a string and that a Subnet needs a CidrBlock, but it does not know whether the AMI exists in your region, whether the CIDR overlaps a VPC you already own, or whether the IAM policy you attached is sufficient. Those failures still arrive from CloudFormation at stack time.

The required-property check is also deferred, which is the sharpest edge in the design. A long builder script that constructs dozens of resources will not report a missing required field until the final serialization call. If that call sits at the bottom of a module, the traceback points at the print statement rather than at the resource that is actually incomplete. The README's error example shows the message format, which includes both the resource type and the logical title, so the information is there; it just arrives late.

Coverage is bounded by the resource list. The README points to two generated documents in the repository, resources_aws.md and resources_openstack.md, for the currently supported types. A newly launched AWS service, or a property added to an existing one, is not available until the library is updated. The practical consequence is that troposphere tracks the CloudFormation specification on its own release schedule, and a brand new resource type may force you to fall back to raw dictionaries inside the template.

troposphere against Terraform and against plain CloudFormation YAML

Terraform and troposphere both let you describe AWS infrastructure in a text format, but they sit at different layers. Terraform is a provisioning tool with its own language, a state file that records what it created, and a plan step that diffs desired against actual before applying. troposphere is a generator: it produces a CloudFormation template and stops. The state is whatever CloudFormation recorded for the stack, and the diff is whatever CloudFormation computes. If you want drift detection, import of existing resources, or a plan output before changes, that comes from CloudFormation or from another tool, not from troposphere.

The closer comparison is plain CloudFormation YAML. Both end at the same API. The difference is where errors appear. With YAML, a mistyped property name is caught by CloudFormation validation or by the stack operation; with troposphere, an unknown attribute raises AttributeError in the Python process before any AWS call. The trade-off is that the template is now code. Reviewing a diff means reading Python, and the generated JSON is an artifact rather than the source of truth. Teams that want the template itself to be the reviewable artifact should stay with YAML.

Maintenance, releases and licence

The repository is not archived, and the last push was on 2026-09-20. The most recent release listed is 4.11.0, dated 2026-09-19, following 4.10.2 in May 2026 and 4.10.1 in February 2026. That cadence is consistent with a library that must keep pace with the CloudFormation resource specification, and it means upgrade cost is mainly a function of how far behind your pinned version is. The CHANGELOG.rst file at the repository root is where the project records what changed between releases; read it before bumping, because resource classes gain and change properties over time.

The licence situation needs one clarification. The README carries a BSD-2-Clause badge and links to the BSD-2-Clause text, and the repository has a LICENSE file. The package.json in the repository declares BSD-3-Clause. These are not the same licence, and the discrepancy is worth resolving with the LICENSE file itself before you rely on either label. Both are permissive and neither imposes a copyleft obligation on your templates, but the specific terms differ. This is a factual observation about the repository, not legal advice; consult your own counsel if the distinction matters to your organisation.

Editorial conclusion

Adopt troposphere if your infrastructure already lives in Python and you want CloudFormation errors raised at object construction rather than at stack creation. Skip it if you need a language-agnostic template format, a state file, or drift detection, since it emits templates and nothing more. Before committing, run the Subnet example in this article against your target region and confirm that the resource types you depend on appear in resources_aws.md.

Frequently asked questions

How do I install troposphere?

The README gives pip install troposphere as the standard path. For AWS policy objects, it recommends pip install troposphere[policy], which also brings in awacs. A source install via python setup.py install is documented for cloned repositories.

Does troposphere validate my CloudFormation template before I deploy it?

It checks property names and Python types when you assign them, and it checks required properties when you serialize the template with to_json() or to_yaml(). It does not verify that an AMI exists in your region or that a CIDR block is valid for your VPC, so those errors still come from CloudFormation.

Which AWS resource types does troposphere support?

The README points to two generated lists in the repository, resources_aws.md and resources_openstack.md, for the currently supported resource types. Support for a resource type depends on the library version, so a newly launched AWS service may not be available until troposphere is updated.

Is troposphere a replacement for Terraform?

No. troposphere generates a CloudFormation template and stops there. Terraform is a provisioning tool with its own state file and a plan step that diffs desired against actual infrastructure, neither of which troposphere provides.

What licence is troposphere released under?

The README shows a BSD-2-Clause badge and links to that licence text, while the repository's package.json declares BSD-3-Clause. The LICENSE file at the repository root is the authoritative source for which terms apply.

Official sources

  1. cloudtools/troposphere on GitHub
  2. Issues
  3. License: BSD-2-Clause
  4. README
  5. Releases
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/cloudtools-troposphere.svg)](https://hysenlabs.com/projects/cloudtools-troposphere)