def report_status(my_settings: settings.Settings, req_type: str, reason: str, logical_res_id: str, status: str):
raw_message = get_messages(my_settings)
if len(raw_message) < 1:
print("No message on queue... so we can't report back")
return 1
messages = [parse_message(m) for m in raw_message]
filtered_messages = [m for m in messages if m.get('RequestType') == req_type]
if logical_res_id != "":
filtered_messages = [m for m in messages if m.get('LogicalResourceId') == logical_res_id]
if len(filtered_messages) < 1:
print("No message of type '{}', so unable to report back to CloudFormation".format(req_type))
return 1
for message in filtered_messages:
response_for_cloud_formation = build_payload(message, status, reason)
response_url_full = message.get('ResponseURL')
response_url, response_params = response_url_full.split('?')
json_response = json.dumps(response_for_cloud_formation)
print("Posting SQS response\n{}".format(json_response))
response = requests.put(
url=response_url, params=response_params,
data=str.encode(json_response)
)
if response.status_code != 200:
print("Failed posting message {}".format(response))
print("{}\n".format(response.text))
return 1
print("Deleting message", message.get('ReceiptHandle'))
delete_messages(my_settings, message)
return 0
评论列表
文章目录