I'm running a Python script via AWS Systems Manger in an automation document - also called a runbook. The script is invoked via action aws:executeScript and the selected runtime is python3.7.
All available examples only show how to return data from the script. How could I indicate the script has failed its job? This appears to be undocumented.
I tried to sys.exit(1)
and also to raise Exception('oh noes')
. Both crash the executor. Unfortunately this completely hides all stdout/stderr of the script and leaves me with the message:
Step fails when it is Poll action status for completion. Traceback (most recent call last): File "/tmp/some-path/customer_script.py", line 23, in main sys.exit(1) SystemExit - 1. Please refer to Automation Service Troubleshooting Guide for more diagnosis details.
The handler method expects two arguments (events
and context
). Again, it appears completely undocumented what the content of these objects might be. events
seems to be a dict with the arguments passed to the script. context
is some object, but according do dir(context)
there is no useful method on that object that would allow me to return a failed state:
['__class__', '__contains__', '__delattr__', '__delitem__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'clear', 'copy', 'fromkeys', 'get', 'items', 'keys', 'pop', 'popitem', 'setdefault', 'update', 'values']