in source/Orchestrator/check_ssm_doc_state.py [0:0]
def _add_doc_state_to_answer(doc, account, region, answer):
# Connect to APIs
ssm = _get_ssm_client(
account,
ORCH_ROLE_NAME,
region
)
# Validate input
try:
docinfo = ssm.describe_document(
Name=doc
)['Document']
doctype = docinfo.get('DocumentType', 'unknown')
if doctype != "Automation":
answer.update({
'status':'ERROR',
'message':'Document Type is not "Automation": ' + str(doctype)
})
LOGGER.error(answer.message)
docstate = docinfo.get('Status', 'unknown')
if docstate != "Active":
answer.update({
'status':'NOTACTIVE',
'message':'Document Status is not "Active": ' + str(docstate)
})
LOGGER.error(answer.message)
answer.update({
'status':'ACTIVE'
})
except ClientError as ex:
exception_type = ex.response['Error']['Code']
if exception_type in "InvalidDocument":
answer.update({
'status':'NOTFOUND',
'message': f'Document {doc} does not exist.'
})
LOGGER.error(answer.message)
else:
answer.update({
'status':'CLIENTERROR',
'message':'An unhandled client error occurred: ' + exception_type
})
LOGGER.error(answer.message)
except Exception as e:
answer.update({
'status':'ERROR',
'message':'An unhandled error occurred: ' + str(e)
})
LOGGER.error(answer.message)