Created
March 16, 2016 17:07
-
-
Save pidah/b00267aff067fa1e3064 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from st2actions.runners.pythonrunner import Action | |
import json | |
class CloudFormationSpec(Action): | |
def run(self, payload, config): | |
# take the payload name and replace any non-alphanumerical characters with "-" | |
# to create a name for the database | |
try: | |
stack_name = "pidah-test-bucket" | |
stack_dict = { "Resources" : { "dontkickthebucket" : { "Type" : "AWS::S3::Bucket" }}} | |
template_body = json.dumps(stack_dict) | |
except: | |
self.logger.exception('Cannot create valid name for Cloudformation Stack!') | |
raise | |
l = dict(self.config.get('cloudformation', {})) | |
newpayload = { | |
'stack_name': stack_name, | |
'template_body': template_body | |
} | |
# Parse through config.yaml for cloudformation:. If cloudformation.key exists in labels.keys(), | |
# use label.value otherwise use default value from config.yaml | |
# then add to newpayload dict. | |
for i in l: | |
if i in payload['labels']: | |
key = i | |
value = payload['labels'][i] | |
newpayload[key] = value | |
else: | |
key = i | |
valuealt = l[i] | |
newpayload[key] = valuealt | |
return newpayload | |
Error message I get : | |
==> st2actionrunner.11325.log <== | |
2016-03-16 17:00:34,366 139662311744368 AUDIT log [-] Liveaction completed (liveaction_db={'status': 'failed', 'start_timestamp': '2016-03-16 17:00:27.250088+00:00', 'parameters': {u'payload': {u'resource': u'ADDED', u'object_kind': u'ThirdPartyResource', u'labels': {u'resource': u's3', u'stack': u'cloudformation'}, u'namespace': u'default', u'name': u'test-cloudformation.prsn.io', u'uid': u'948cb35c-eb98-11e5-aa08-0a5a43706445'}}, 'runner_info': {u'hostname': u'ip-10-253-17-26', u'pid': 11325}, 'callback': {}, 'notify': None, 'result': {'tasks': [{'name': 'cloudformation_spec', 'workflow': None, 'created_at': '2016-03-16T17:00:28.439363+00:00', 'updated_at': '2016-03-16T17:00:30.979725+00:00', 'state': u'succeeded', 'result': {u'stdout': u'', u'exit_code': 0, u'stderr': u'', u'result': {u'stack_name': u'pidah-test-bucket', u'template_body': u'{"Resources": {"dontkickthebucket": {"Type": "AWS::S3::Bucket"}}}', u'Resources': {u'dontkickthebucket': {u'Type': u'AWS::S3::Bucket'}}}}, 'id': 'cloudformation_spec', 'execution_id': '56e9912cc245b02c3d7f8f1d'}, {'name': 'create_cloudformation_stack', 'workflow': None, 'created_at': '2016-03-16T17:00:30.985524+00:00', 'updated_at': '2016-03-16T17:00:34.212299+00:00', 'state': u'failed', 'result': {u'stdout': u'', u'exit_code': 1, u'stderr': u'Traceback (most recent call last):\n File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2actions/runners/python_action_wrapper.py", line 116, in <module>\n obj.run()\n File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2actions/runners/python_action_wrapper.py", line 61, in run\n output = action.run(**self._parameters)\n File "/opt/stackstorm/packs/aws/actions/run.py", line 18, in run\n return self.do_method(module_path, cls, action, **kwargs)\n File "/opt/stackstorm/packs/aws/actions/lib/action.py", line 94, in do_method\n resultset = getattr(obj, action)(**kwargs)\n File "/opt/stackstorm/virtualenvs/aws/lib/python2.7/site-packages/boto/cloudformation/connection.py", line 403, in create_stack\n body = self._do_request(\'CreateStack\', params, \'/\', \'POST\')\n File "/opt/stackstorm/virtualenvs/aws/lib/python2.7/site-packages/boto/cloudformation/connection.py", line 304, in _do_request\n raise self.ResponseError(response.status, response.reason, body=body)\nboto.exception.BotoServerError: BotoServerError: 400 Bad Request\n{"Error":{"Code":"ValidationError","Message":"Either Template URL or Template Body must be specified.","Type":"Sender"},"RequestId":"98b91248-eb98-11e5-80d5-d79894d0ef3c"}\n', u'result': None}, 'id': 'create_cloudformation_stack', 'execution_id': '56e9912fc245b02c3d7f8f20'}]}, 'context': {u'trigger_instance': {u'id': u'56e9912ac245b02c6e6c0db3', u'name': None}, u'trace_context': {u'id_': u'56e9912ac245b02c6e6c0db4', u'trace_tag': u'trigger_instance-56e9912ac245b02c6e6c0db3'}, u'rule': {u'id': u'56e9643cc245b02d09cdc8f5', u'name': u'kubernetes_cloudformation_create'}, u'user': u'stanley'}, 'action': u'kubernetes.cloudformation_create_chain', 'id': '56e9912bc245b02c6e6c0dba', 'end_timestamp': '2016-03-16 17:00:34.229132+00:00'}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment