python - 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。
对此有何解决方案?
解决方案
我发现解决方案只是在代码中设置了睡眠/等待。time.sleep(10) 进入代码解决了这个问题
推荐阅读
- graph - 树证书的顶点度数
- odoo-8 - 原始模块的退出字段上的 sql_cosntraints
- javascript - 将变量导入 HTML
- tkinter - Where can I find tkinter documentation?
- docker - docker内部的Docker:卷已安装,但为空
- bash - 使用 sed 替换 while read 循环中的单行
- laravel - laravel 存储方法不在其他操作系统或机器上显示图像
- php - laravel 中的命名空间控制器和路由
- jena - 在 Jena API 中,如何使用 Jena RULE 计算一个班级的人数?
- dart - 将屏幕均匀地分成4个不同的部分