{"id":7814,"date":"2015-10-29T13:51:45","date_gmt":"2015-10-29T13:51:45","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2015\/10\/29\/cloudtools-troposphere\/"},"modified":"2015-10-29T13:51:45","modified_gmt":"2015-10-29T13:51:45","slug":"cloudtools-troposphere","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2015\/10\/29\/cloudtools-troposphere\/","title":{"rendered":"cloudtools\/troposphere"},"content":{"rendered":"<p>=========== troposphere ===========<\/p>\n<p>\u2026 image:: https:\/\/pypip.in\/version\/troposphere\/badge.svg?text=version&amp;style=flat :target: https:\/\/pypi.python.org\/pypi\/troposphere<\/p>\n<p>\u2026 image:: https:\/\/travis-ci.org\/cloudtools\/troposphere.png?branch=master :target: https:\/\/travis-ci.org\/cloudtools\/troposphere<\/p>\n<h2>About<\/h2>\n<p>troposphere &#8211; library to create <code>AWS CloudFormation<\/code>_ descriptions<\/p>\n<p>The troposphere library allows for easier creation of the AWS CloudFormation JSON by writing Python code to describe the AWS resources. Troposphere also includes some basic support for <code>OpenStack resources<\/code>_ via heat.<\/p>\n<p>To facilitate catching CloudFormation or JSON errors early the library has property and type checking built into the classes.<\/p>\n<h2>Installation Instructions<\/h2>\n<p>troposphere can be installed using the pip distribution system for python by issuing::<\/p>\n<pre><code>$ pip install troposphere\n<\/code><\/pre>\n<p>Alternatively, you can run use setup.py to install by cloning this repository and issuing::<\/p>\n<pre><code># python setup.py install\n<\/code><\/pre>\n<h2>Examples<\/h2>\n<p>A simple example to create an instance would look like this::<\/p>\n<pre><code>&gt;&gt;&gt; from troposphere import Ref, Template\n&gt;&gt;&gt; import troposphere.ec2 as ec2\n&gt;&gt;&gt; t = Template()\n&gt;&gt;&gt; instance = ec2.Instance(\"myinstance\")\n&gt;&gt;&gt; instance.ImageId = \"ami-951945d0\"\n&gt;&gt;&gt; instance.InstanceType = \"t1.micro\"\n&gt;&gt;&gt; t.add_resource(instance)\n\n&gt;&gt;&gt; print(t.to_json())\n{\n    \"Resources\": {\n        \"myinstance\": {\n            \"Properties\": {\n                \"ImageId\": \"ami-951945d0\",\n                \"InstanceType\": \"t1.micro\"\n            },\n            \"Type\": \"AWS::EC2::Instance\"\n        }\n    }\n}\n<\/code><\/pre>\n<p>Alternatively, parameters can be used instead of properties::<\/p>\n<pre><code>&gt;&gt;&gt; instance = ec2.Instance(\"myinstance\", ImageId=\"ami-951945d0\", InstanceType=\"t1.micro\")\n&gt;&gt;&gt; t.add_resource(instance)\n\n<\/code><\/pre>\n<p>And add_resource() returns the object to make it easy to use with Ref()::<\/p>\n<pre><code>&gt;&gt;&gt; instance = t.add_resource(ec2.Instance(\"myinstance\", ImageId=\"ami-951945d0\", InstanceType=\"t1.micro\"))\n&gt;&gt;&gt; Ref(instance)\n\n<\/code><\/pre>\n<h2>Examples of the error checking (full tracebacks removed for clarity):<\/h2>\n<p>Incorrect property being set on AWS resource::<\/p>\n<pre><code>&gt;&gt;&gt; import troposphere.ec2 as ec2\n&gt;&gt;&gt; ec2.Instance(\"ec2instance\", image=\"i-XXXX\")\nTraceback (most recent call last):\n...\nAttributeError: AWS::EC2::Instance object does not support attribute image\n<\/code><\/pre>\n<p>Incorrect type for AWS resource property::<\/p>\n<pre><code>&gt;&gt;&gt; ec2.Instance(\"ec2instance\", ImageId=1)\nTraceback (most recent call last):\n...\nTypeError: ImageId is , expected \n<\/code><\/pre>\n<p>Missing required property for the AWS resource::<\/p>\n<pre><code>&gt;&gt;&gt; from troposphere import Template\n&gt;&gt;&gt; import troposphere.ec2 as ec2\n&gt;&gt;&gt; t = Template()\n&gt;&gt;&gt; t.add_resource(ec2.Instance(\"ec2instance\", InstanceType=\"m3.medium\"))\n\n&gt;&gt;&gt; print(t.to_json())\nTraceback (most recent call last):\n...\nValueError: Resource ImageId required in type AWS::EC2::Instance\n<\/code><\/pre>\n<h2>Currently supported AWS resource types<\/h2>\n<ul>\n<li>AWS::AutoScaling<\/li>\n<li>AWS::CloudFormation<\/li>\n<li>AWS::CloudFront<\/li>\n<li>AWS::CloudTrail<\/li>\n<li>AWS::CloudWatch<\/li>\n<li>AWS::DynamoDB<\/li>\n<li>AWS::EC2<\/li>\n<li>AWS::ElastiCache<\/li>\n<li>AWS::ElasticBeanstalk<\/li>\n<li>AWS::ElasticLoadBalancing<\/li>\n<li>AWS::IAM<\/li>\n<li>AWS::KINESIS<\/li>\n<li>AWS::Logs<\/li>\n<li>AWS::OPSWORKS<\/li>\n<li>AWS::RDS<\/li>\n<li>AWS::REDSHIFT<\/li>\n<li>AWS::Route53<\/li>\n<li>AWS::S3<\/li>\n<li>AWS::SDB<\/li>\n<li>AWS::SNS<\/li>\n<li>AWS::SQS<\/li>\n<\/ul>\n<ul>\n<li>OS::Neutron::Firewall<\/li>\n<li>OS::Neutron::FirewallPolicy<\/li>\n<li>OS::Neutron::FirewallRule<\/li>\n<li>OS::Neutron::FloatingIP<\/li>\n<li>OS::Neutron::FloatingIPAssociation<\/li>\n<li>OS::Neutron::HealthMonitor<\/li>\n<li>OS::Neutron::Pool<\/li>\n<li>OS::Neutron::LoadBalancer<\/li>\n<li>OS::Neutron::Net<\/li>\n<li>OS::Neutron::PoolMember<\/li>\n<li>OS::Neutron::Port<\/li>\n<li>OS::Neutron::SecurityGroup<\/li>\n<li>OS::Nova::FloatingIP<\/li>\n<li>OS::Nova::FloatingIPAssociation<\/li>\n<li>OS::Nova::KeyPair<\/li>\n<li>OS::Nova::Server<\/li>\n<\/ul>\n<p>Todo:<\/p>\n<ul>\n<li>\n<p>Add additional validity checks<\/p>\n<\/li>\n<li>\n<p>Add missing AWS resource types:<\/p>\n<ul>\n<li>AWS::CloudFormation::CustomResource<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2>Duplicating a single instance sample would look like this<\/h2>\n<p>\u2026 code::<\/p>\n<pre><code># Converted from EC2InstanceSample.template located at:\n# http:\/\/aws.amazon.com\/cloudformation\/aws-cloudformation-templates\/\n\nfrom troposphere import Base64, FindInMap, GetAtt\nfrom troposphere import Parameter, Output, Ref, Template\nimport troposphere.ec2 as ec2\n\n\ntemplate = Template()\n\nkeyname_param = template.add_parameter(Parameter(\n    \"KeyName\",\n    Description=\"Name of an existing EC2 KeyPair to enable SSH \"\n                \"access to the instance\",\n    Type=\"String\",\n))\n\ntemplate.add_mapping('RegionMap', {\n    \"us-east-1\":      {\"AMI\": \"ami-7f418316\"},\n    \"us-west-1\":      {\"AMI\": \"ami-951945d0\"},\n    \"us-west-2\":      {\"AMI\": \"ami-16fd7026\"},\n    \"eu-west-1\":      {\"AMI\": \"ami-24506250\"},\n    \"sa-east-1\":      {\"AMI\": \"ami-3e3be423\"},\n    \"ap-southeast-1\": {\"AMI\": \"ami-74dda626\"},\n    \"ap-northeast-1\": {\"AMI\": \"ami-dcfa4edd\"}\n})\n\nec2_instance = template.add_resource(ec2.Instance(\n    \"Ec2Instance\",\n    ImageId=FindInMap(\"RegionMap\", Ref(\"AWS::Region\"), \"AMI\"),\n    InstanceType=\"t1.micro\",\n    KeyName=Ref(keyname_param),\n    SecurityGroups=[\"default\"],\n    UserData=Base64(\"80\")\n))\n\ntemplate.add_output([\n    Output(\n        \"InstanceId\",\n        Description=\"InstanceId of the newly created EC2 instance\",\n        Value=Ref(ec2_instance),\n    ),\n    Output(\n        \"AZ\",\n        Description=\"Availability Zone of the newly created EC2 instance\",\n        Value=GetAtt(ec2_instance, \"AvailabilityZone\"),\n    ),\n    Output(\n        \"PublicIP\",\n        Description=\"Public IP address of the newly created EC2 instance\",\n        Value=GetAtt(ec2_instance, \"PublicIp\"),\n    ),\n    Output(\n        \"PrivateIP\",\n        Description=\"Private IP address of the newly created EC2 instance\",\n        Value=GetAtt(ec2_instance, \"PrivateIp\"),\n    ),\n    Output(\n        \"PublicDNS\",\n        Description=\"Public DNSName of the newly created EC2 instance\",\n        Value=GetAtt(ec2_instance, \"PublicDnsName\"),\n    ),\n    Output(\n        \"PrivateDNS\",\n        Description=\"Private DNSName of the newly created EC2 instance\",\n        Value=GetAtt(ec2_instance, \"PrivateDnsName\"),\n    ),\n])\n\nprint(template.to_json())\n<\/code><\/pre>\n<h2>Community<\/h2>\n<p>We have a google group, cloudtools-dev_, where you can ask questions and engage with the troposphere community. Issues &amp; pull requests are always welcome!<\/p>\n<p>\u2026 _<code>AWS CloudFormation<\/code>: http:\/\/aws.amazon.com\/cloudformation \u2026 _<code>OpenStack resources<\/code>: http:\/\/docs.openstack.org\/developer\/heat\/template_guide\/openstack.html \u2026 _cloudtools-dev: https:\/\/groups.google.com\/forum\/#!forum\/cloudtools-dev<\/p>\n","protected":false},"excerpt":{"rendered":"<p>=========== troposphere =========== \u2026 image:: https:\/\/pypip.in\/version\/troposphere\/badge.svg?text=version&amp;style=flat :target: https:\/\/pypi.python.org\/pypi\/troposphere \u2026 image:: https:\/\/travis-ci.org\/cloudtools\/troposphere.png?branch=master :target: https:\/\/travis-ci.org\/cloudtools\/troposphere About troposphere &#8211; library to create AWS CloudFormation_ descriptions The troposphere library allows for easier creation of the AWS CloudFormation JSON by writing Python code to describe the AWS resources. Troposphere also includes some basic support for OpenStack resources_ via heat. To [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-7814","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7814","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=7814"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7814\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=7814"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=7814"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=7814"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}