【发布时间】:2021-10-20 17:16:18
【问题描述】:
我正在尝试执行 SSM 自动化,然后应用服务员等待执行完成,但我遇到了 InvocationDoesNotExist 异常。
我的代码如下:
# Get the SSM client
client = boto3.client('ssm')
#Start the automation runbook and capture response
response = client.start_automation_execution(
DocumentName='document_name',
DocumentVersion='$LATEST',
Parameters={
'RestoredInstanceIds': [
'i-02fee85b181a1gb55',
]
}
)
print(response)
waiter = client.get_waiter('command_executed')
waiter.wait(
CommandId=response["AutomationExecutionId"],
InstanceId='i-02fee85b181a1gb55'
)
print("DONE")
报错如下:botocore.exceptions.WaiterError: Waiter CommandExecuted failed: An error occurred (InvocationDoesNotExist):
打印(响应)工作正常,并为我提供正确的执行 ID:
{'AutomationExecutionId': '9a433866-...', 'ResponseMetadata': {'RequestId': '9a433866-...', 'HTTPStatusCode': 200, 'HTTPHeaders': {'server': 'Server', 'date': 'Wed, 18 Aug 2021 23:21:32 GMT', 'content-type': 'application/x-amz-json-1.1', 'content-length': '64', 'connection': 'keep-alive', 'x-amzn-requestid': '9a433866...'}, 'RetryAttempts': 0}}
有人可以帮忙解释一下为什么这不起作用吗?
【问题讨论】:
-
我相信命令服务员是为用
send_command()创建的命令,它返回一个CommandId。因为好像没有自动执行的服务员,需要手动轮询get_automation_execution -
哦,是的,这是有道理的。有什么方法可以创建自定义服务员以获取自动化执行?
-
是的,只需使用一个 while 循环并调用
get_automation_execution并在调用之间休眠,直到状态是被认为是完整的状态之一。文档中有一个所有状态的列表boto3.amazonaws.com/v1/documentation/api/latest/reference/…
标签: python python-3.x amazon-web-services boto3 aws-ssm