我正在尝试对fargate管理的ecs容器运行命令。我可以建立连接并成功执行,但我无法从python脚本中的上述命令获得响应
import boto3
import pprint as pp
client = boto3.client("ecs")
cluster = "my-mundane-cluster-name"
def main():
task_arns = client.list_tasks(cluster=cluster, launchType="FARGATE")
for task_arn in task_arns.get("taskArns", []):
cmd_out = client.execute_command(
cluster=cluster,
command="ls",
interactive=True,
task=task_arn,
)
pp.pprint(f"{cmd_out}")
if __name__ == "__main__":
main()
我用ls
替换了该命令,但出于所有目的,流程都是相同的。这是我得到的休息
{
'clusterArn': 'arn:aws:ecs:■■■■■■■■■■■■:■■■■■■:cluster/■■■■■■',
'containerArn': 'arn:aws:ecs:■■■■■■■■■■■■:■■■■■■:container/■■■■■■/■■■■■■/■■■■■■■■■■■■■■■■■■',
'containerName': '■■■■■■',
'interactive': True,
'session': {
'sessionId': 'ecs-execute-command-■■■■■■■■■',
'streamUrl': '■■■■■■■■■■■■■■■■■■',
'tokenValue': '■■■■■■■■■■■■■■■■■■'
},
'taskArn': 'arn:aws:ecs:■■■■■■■■■■■■:■■■■■■■■■:task/■■■■■■■■■/■■■■■■■■■■■■■■■■■■',
'ResponseMetadata': {
'RequestId': '■■■■■■■■■■■■■■■■■■',
'HTTPStatusCode': 200,
'HTTPHeaders': {
'x-amzn-requestid': '■■■■■■■■■■■■■■■■■■',
'content-type': 'application/x-amz-json-1.1',
'content-length': '■■■',
'date': 'Thu, 29 Jul 2021 02:39:24 GMT'
},
'RetryAttempts': 0
}
}
我尝试以非交互方式运行该命令,以查看它是否返回响应,但sdk显示Interactive is the only mode supported currently
。我也试着在网上搜索如何做到这一点的线索,但没有运气
非常感谢您的帮助
命令输出的值位于位于
streamId
的文档流中。您必须初始化一个新会话,并向其传递sessionID以检索其内容粗略的例子:
参考资料
SSM:https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ssm.html
SSM#get#U文档:https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ssm.html#SSM.Client.get_document
快速解决方法是使用
logging
而不是pprint
:相关问题 更多 >
编程相关推荐