Registry / aws / troposphere

troposphere

JSON →
library4.10.2pypypi✓ verified 25d ago

Troposphere is an open-source Python library that simplifies the creation of AWS CloudFormation JSON and YAML templates by allowing developers to define AWS resources using Python code. It offers a Pythonic syntax, built-in property and type checking to catch errors early, and promotes modular code. The library is actively maintained with frequent updates driven by the latest AWS Resource Specification, and also provides basic support for OpenStack Heat resources.

pip install troposphere
INSTALL
IMPORT
SIG · TROPOSPHERE
T
troposphere
awspythonv4.10.2
Install
2.6s avg
Import
261ms
Disk
34MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v4.10.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.265s · 35MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 2.6s · import 0.256s · 36MB
34MB installed
● package 34MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Template
from troposphere import Template
ec2 (example service)
import troposphere.ec2 as ec2
Ref, GetAtt, Join
from troposphere import Ref, GetAtt, Join

This quickstart code demonstrates how to create a basic AWS CloudFormation template using Troposphere to launch an EC2 instance. It defines an instance with a specific AMI, instance type, and key pair, and then outputs its public DNS name. Remember to replace `ami-0c55b159cbfafe1f0` and `my-ssh-key` with valid values for your AWS region and account. The template is then printed as a JSON string.

from troposphere import Template, Ref import troposphere.ec2 as ec2 t = Template() t.set_description("AWS CloudFormation template to create a single EC2 instance.") instance_name = "MyWebServer" instance = t.add_resource(ec2.Instance( instance_name, ImageId="ami-0c55b159cbfafe1f0", # Example AMI ID (Ubuntu 20.04 LTS HVM, SSD Volume Type) InstanceType="t2.micro", KeyName="my-ssh-key", # Replace with your EC2 Key Pair name Tags=[ {"Key": "Name", "Value": instance_name} ] )) # Output the Public DNS name of the instance t.add_output( [Ref(instance.get_att("PublicDnsName"))], "Public DNS Name for the new EC2 instance", "PublicDns" ) print(t.to_json(indent=2))
Debug
Known issues
breakingVersion 4.0.0 introduced breaking changes due to a refactoring for auto-generation from the AWS Resource Specification. Specifically, properties for `AWS::EC2 - Ipv6Addresses` were changed from an `AWSHelperFn` class to an `AWSProperty`, and `SpotFleet::LaunchSpecifications` properties such as `IamInstanceProfile`, `NetworkInterfaces`, and `Placement` were updated to use dedicated specification classes (e.g., `IamInstanceProfileSpecification`).
fix
Review your existing templates that use affected `AWS::EC2` and `SpotFleet` properties and update them to use the new class structures or property types as per the 4.0.0 changelog.
affects: >=4.0.0
gotchaTroposphere closely mirrors AWS CloudFormation's underlying structure. This means that while Troposphere itself may not have a 'breaking change', fundamental changes or deprecations in the AWS CloudFormation service or resource specifications will directly impact how you construct your Troposphere templates. Users should regularly consult the AWS CloudFormation documentation alongside Troposphere's.
fix
Stay informed about AWS CloudFormation updates and specification changes. Regularly validate your generated CloudFormation templates against the latest AWS service definitions.
affects: All versions
gotchaTroposphere classes are frequently updated to reflect the latest AWS Resource Specification versions. While this ensures support for new AWS features, it can lead to changes in property names, validation rules, or available attributes. For instance, `Transfer.WebApp.EndpointDetails` was renamed to `WebAppEndpointDetails` in 4.10.1.
fix
Monitor Troposphere's changelog for 'Updates from spec version X.Y.Z' entries and be prepared to make minor adjustments to your code if resource properties are renamed, removed, or have updated validation requirements.
affects: All versions
gotchaThe `gen.py` script, used to auto-generate Troposphere classes from the AWS Resource Specification, is typically only available by cloning the repository and not when installing `troposphere` via pip. This makes it difficult for users to generate custom or locally-updated resource classes without working directly from the source repository.
fix
If you require custom resource generation or need to work with a very specific, unreleased version of the CloudFormation spec, consider cloning the Troposphere GitHub repository to access the `gen.py` script.
affects: All versions
Errors
Common errors & fixes
TypeError: 'Ref' object is not subscriptable
You are attempting to use a `Ref` object as if it were a dictionary, list, or a direct string, which `Ref` objects do not support for direct manipulation.
fix
Embed `Ref` objects within CloudFormation intrinsic functions like `Sub`, `Join`, or `GetAtt`, or pass them directly to resource properties that explicitly accept intrinsic function objects.
ValueError: <ResourceType> requires <PropertyName>
You have instantiated a Troposphere resource without providing a value for one of its mandatory properties.
fix
Ensure all required properties for the resource type are provided during its instantiation. Consult the AWS CloudFormation documentation or Troposphere's source for the specific resource.
TypeError: Parameter <parameter_name> must be a <type>
You have provided a value of an incorrect data type for a resource property (e.g., passing a string when a list is expected, or an integer when a string is required).
fix
Verify the expected Python data type for the property and provide a value of the correct type (e.g., `str`, `int`, `list`, `dict`), or ensure intrinsic functions like `Ref` or `GetAtt` are used appropriately where expected.
ModuleNotFoundError: No module named 'troposphere'
The `troposphere` library is not installed in your current Python environment or your environment is not correctly configured.
fix
Install the library using pip: `pip install troposphere`.
Upgrade
Version history
4.10.2latest on PyPI · released May 16, 2026
Audit
Dependencies
pythonrequiredRequired runtime environment.
awacsoptionalRecommended for easier generation of IAM policies.
Agent activity
17 hits · last 30 days
node
16
Resources
troposphere — pip install troposphere · libregistry