Package short description.
Project description
Welcome to troposphere_mate Documentation
troposphere is a great Python library allow you to define AWS CloudFormation Resource in Python Class. But due to its implementation, IDLE can’t use attribute auto hint, and Type hint doesn’t work as well. troposphere_mate provides API exactly same as troposphere, but with availalbe Properties auto hint feature and type hint enabled. troposphere_mate is a thin wrapper layer on top of troposphere.
My goal is 100% API compatible to troposphere. Basically, you just need to replace from troposphere import Template, Ref, Tags, GetAtt to from troposphere_mate import Template, Ref, Tags, GetAtt.
Here’s how it looks like in IDLE:
How troposphere implements:
# content of troposphere.ec2.py class Instance(AWSObject): resource_type = "AWS::EC2::Instance" props = { 'InstanceType': (basestring, False), 'SubnetId': (basestring, False), 'KeyName': (basestring, False), ... }
How troposphere_mate implements:
@attr.s class Instance(AWSObject): title = attr.ib() # type: str InstanceType = attr.ib(default=NOTHING) # type: str SubnetId = attr.ib(default=NOTHING) # type: str KeyName = attr.ib(default=NOTHING) # type: str template = attr.ib(default=None) # type: Template validation = attr.ib(default=True) # type: bool _aws_object_class = troposphere.ec2.Instance
Additional Features
Auto Reference
Sometimes, you just know you need to associate one AWS Resource to another, but you have to lookup the Document to find out which Property and what is the Syntax to do that.
For example, if you want to associate an IAM Role, VPC Subnet, Security Group to a Lambda Function.
Suppose you already have:
from troposphere_mate import ec2, awslambda, iam
tpl = Template()
iam_role = iam.Role(
title="MyIamRole",
template=tpl,
RoleName="lambda-basic-execution",
AssumeRolePolicyDocument={},
)
vpc = ec2.VPC(
title="MyVPC",
template=tpl,
CidrBlock="10.53.0.0/16"
)
public_subnet1 = ec2.Subnet(
title="PublicSubnet1",
template=tpl,
CidrBlock="10.53.0.0/16",
VpcId=Ref(vpc)
)
public_subnet2 = ec2.Subnet(
title="PublicSubnet2",
template=tpl,
CidrBlock="10.53.2.0/16",
VpcId=Ref(vpc)
)
sg = ec2.SecurityGroup(
title="LambdaSG",
template=tpl,
GroupDescription="Just a SG"
)
lbd_func = awslambda.Function(
title="MyFunc",
template=tpl,
Code=awslambda.Code(
S3Bucket="my-bucket",
S3Key="0.0.1.zip",
),
Handler="my_func.handler",
Role="arn:aws:iam::111122223333:role/todo",
Runtime="python3.6"
)
With troposphere_mate, you just need to do this:
from troposphere_mate import associate
associate(lbd_func, iam_role) # order doesn't matter, associate(iam_role, lbd_func)
associate(lbd_func, sg)
associate(lbd_func, public_subnet1)
associate(lbd_func, public_subnet2)
In other word, you don’t need to remember the properties and the syntax.
from troposphere import Ref
from troposphere import awslambda
lbd_func.Role = Ref(iam_role)
lbd_func.VpcConfig = awslambda.VPCConfig(
SecurityGroupIds=[
Ref(sg)
],
SubnetIds=[
Ref(public_subnet1),
Ref(public_subnet2),
]
)
If you want to contribute your auto-associate logic to troposphere_mate, please submit issue or help me to improve. Here’s an example.
Install
troposphere_mate is released on PyPI, so all you need is:
$ pip install troposphere_mate
To upgrade to latest version:
$ pip install --upgrade troposphere_mate
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for troposphere_mate-0.0.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b727391343180ec437bf0deccdb2517ea2a93c1d2a6391f71190890bb58e67ea |
|
MD5 | 5709d49f45727cfae376ff47876c7ea5 |
|
BLAKE2b-256 | ca44af40014f18004d6f20bd38a7aeff11df0cc27eb8863cdb9126af16674c31 |