Skip to content

Commit

Permalink
Added failure reason to CloudFormation response object. This provides…
Browse files Browse the repository at this point in the history
… nice failure messages through the CloudFormation UI/APIs
  • Loading branch information
Christopher Mutzel committed Mar 31, 2016
1 parent d4b9170 commit e92bfa0
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion pycfn_custom_resource/lambda_backed.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ def _get_source_attributes(self, success):
"PhysicalResourceId":
self.physicalresourceid if self.physicalresourceid else str(uuid.uuid4())
}
try:
if not success:
reason = str(self.failure_exception)
source_attributes["Reason"] = reason
except:
log.warning(u"Could not convert failure exception to string in CloudFormation response payload. Dropping...")

return source_attributes

def invoke_chained_lambda(self):
Expand Down Expand Up @@ -144,14 +151,19 @@ def process_event(self):
self.requesttype, self.result_text)
success = False

except:
except Exception as exception:
# Send the exception back to CloudFormation
self.failure_exception = exception

# log details to the CloudWatch?
e = sys.exc_info()
log.error(u"Command %s-%s failed", self.logicalresourceid, self.requesttype)
log.debug(u"Command %s error: %s", self.logicalresourceid, str(e[1]))
log.debug(u"Command %s traceback:", self.logicalresourceid)
traceback.print_tb(e[2])
success = False


log.debug(u"Command %s-%s processing %s", self.logicalresourceid, self.requesttype, self.processing)
log.debug(u"Command %s-%s success %s", self.logicalresourceid, self.requesttype, success)
if self.processing and success:
Expand Down

0 comments on commit e92bfa0

Please sign in to comment.