首页 > 解决方案 > aws boto 传递变量

问题描述

ssm = boto3.client('ssm' )
            instance = 'i-123123'
            response = ssm.send_command( InstanceIds=[ instance ], DocumentName='AWS-RunShellScript', Comment='slack testing', Parameters={ "commands":[ "hostname" ]  } )
            command_id = response['Command']['CommandId']
            command_id.encode("utf-8")
            output = ssm.get_command_invocation(
                CommandId=command_id,
                InstanceId=instance
                )

以上是代码。问题出在 get_command_invocation 中,它不是作为变量传递,而是作为字符串传递,并在错误之下传递

An error occurred (InvocationDoesNotExist) when calling the GetCommandInvocation operation: : InvocationDoesNotExist
Traceback (most recent call last):
File "/var/task/lambda_function.py", line 137, in lambda_handler
InstanceId=instance
File "/var/runtime/botocore/client.py", line 314, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/var/runtime/botocore/client.py", line 612, in _make_api_call
raise error_class(parsed_response, operation_name)
InvocationDoesNotExist: An error occurred (InvocationDoesNotExist) when calling the GetCommandInvocation operation:  

但如果我分别打印 command_id 和实例,它们实际上是在打印实际的 id。

对此有何解决方案?

标签: pythonamazon-web-servicesboto3ssm

解决方案


我发现解决方案只是在代码中设置了睡眠/等待。time.sleep(10) 进入代码解决了这个问题


推荐阅读