troposphere
troposphere copied to clipboard
Create new object from CFN Yaml definition
Hello. It is a question rather than an issue but unsure where to ask. Basically, let's assume we have a YAML document somewhere and we want to integrate the CFN object it represents into a troposphere object.
If that object has a complex structure with various types expected, it doesn't work. So not sure how we could achieve the above.
Here is a snippet of what I would like to do.
Properties:
AttributeDefinitions:
- AttributeName: "currencyId"
AttributeType: "N"
- AttributeName: "currencyName"
AttributeType: "S"
KeySchema:
- AttributeName: "currencyId"
KeyType: "HASH"
- AttributeName: "currencyName"
KeyType: "RANGE"
ProvisionedThroughput:
ReadCapacityUnits: "5"
WriteCapacityUnits: "5"
TableName: "OreoCurrency"
and the python for it that I hoped would work is
import yaml
content = yaml.load(<ABOVE CONTENT>)
from troposphere.dynamodb import Table
table = Table('sometable', **content['SomeTable']['Properties'])
At the moment I get
>>> table = Table('hello', **dict_['SomeTable']['Properties'])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/john/.venv/lib64/python3.7/site-packages/troposphere/__init__.py", line 127, in __init__
self.__setattr__(k, v)
File "/home/john/.venv/lib64/python3.7/site-packages/troposphere/__init__.py", line 204, in __setattr__
self._raise_type(name, v, expected_type)
File "/home/john/.venv/lib64/python3.7/site-packages/troposphere/__init__.py", line 232, in _raise_type
expected_type))
TypeError: <class 'troposphere.dynamodb.Table'>: hello.AttributeDefinitions is <class 'dict'>, expected [<class 'troposphere.dynamodb.AttributeDefinition'>]
Many thanks :)