Skip to content

Instantly share code, notes, and snippets.

@chriswgerber
Created May 14, 2018 17:38
Show Gist options
  • Save chriswgerber/1fdb34ca4d293f8c34c1fbca09c5252f to your computer and use it in GitHub Desktop.
Save chriswgerber/1fdb34ca4d293f8c34c1fbca09c5252f to your computer and use it in GitHub Desktop.
Python file demonstrating errors with Troposphere Template Generator
#!/usr/bin/env python3
import json
from troposphere.template_generator import TemplateGenerator
JSON_DATA = """\
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Example nested outputs template",
"Parameters": {
"Ec2Instance1": {
"Type": "String",
"Description": "Instance 1 ID"
},
"Ec2Instance2": {
"Type": "String",
"Description": "Instance 2 ID"
}
},
"Resources": {
"ElasticLoadBalancer": {
"Type": "AWS::ElasticLoadBalancing::LoadBalancer",
"Properties": {
"AvailabilityZones": {
"Fn::GetAZs": ""
},
"Instances": [
{
"Ref": "Ec2Instance1"
},
{
"Ref": "Ec2Instance2"
}
],
"Listeners": [
{
"LoadBalancerPort": "80",
"InstancePort": "80",
"Protocol": "HTTP"
}
],
"HealthCheck": {
"Target": "HTTP:80/",
"HealthyThreshold": "3",
"UnhealthyThreshold": "5",
"Interval": "30",
"Timeout": "5"
},
"ConnectionDrainingPolicy": {
"Enabled": "true",
"Timeout": "60"
}
}
}
},
"Outputs": {
"LbSecurityGroup": {
"Description": "LB Security Group",
"Value": {
"Fn::GetAtt": [
"ElasticLoadBalancer",
"SourceSecurityGroup.GroupName"
]
},
"Export": {
"Name": {
"Fn::Sub": "${AWS::StackName}-LbSecurityGroup"
}
}
}
}
}
"""
JSON_TEMPLATE = json.loads(JSON_DATA)
TEMPLATE = TemplateGenerator(JSON_TEMPLATE)
TEMPLATE.to_json()
@chriswgerber
Copy link
Author

troposphere 2.2.1

Error:

Traceback (most recent call last):
  File "./trop-example.py", line 78, in <module>
    TEMPLATE = TemplateGenerator(JSON_TEMPLATE)
  File "[...]/lib/python3.6/site-packages/troposphere/template_generator.py", line 63, in __init__
    self._get_resource_type_cls(v)
  File "[...]/lib/python3.6/site-packages/troposphere/template_generator.py", line 161, in _convert_definition
    return self._create_instance(expected_type, args, ref)
  File "[...]/lib/python3.6/site-packages/troposphere/template_generator.py", line 264, in _create_instance
    expected_type, kwargs[prop_name], prop_name)
  File "[...]/lib/python3.6/site-packages/troposphere/template_generator.py", line 274, in _create_instance
    return cls(title=ref, **args)
  File "[...]/lib/python3.6/site-packages/troposphere/__init__.py", line 343, in __init__
    super(AWSProperty, self).__init__(title, **kwargs)
  File "[...]/lib/python3.6/site-packages/troposphere/__init__.py", line 126, in __init__
    self.__setattr__(k, v)
  File "[...]/lib/python3.6/site-packages/troposphere/__init__.py", line 203, in __setattr__
    self._raise_type(name, value, expected_type)
  File "[...]/lib/python3.6/site-packages/troposphere/__init__.py", line 221, in _raise_type
    expected_type))
TypeError: <class 'troposphere.elasticloadbalancing.ConnectionDrainingPolicy'>: ConnectionDrainingPolicy.Enabled is <class 'str'>, expected <class 'bool'>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment