我想用aws ecs执行容器命令连接到我的容器。
aws ecs execute-command --cluster <cluster> --task <task_id> --container <container_name> --interactive --command "/bin/bash"目前,我需要进入我的aws仪表板并获取任务id,但最近我意识到我可以只使用
aws ecs list-tasks --cluster <cluster> --family <container> | grep -e "arn"**注:我仍然需要从结果中获取实际身份
我想运行第二个输出并使用输出调用第一个输出。
我试过:
aws ecs list-tasks --cluster <cluster>--family <family> | grep -e "arn" | aws ecs execute-command --cluster <cluster> --task $1 --container <container> --interactive --command "/bin/bash"和
aws ecs execute-command --cluster <cluster>--task $(aws ecs list-tasks --cluster <cluster> --family <task-family> | grep -e \"arn\" | awk '{print $1}') --container <container-name> --interactive --command "/bin/bash"有什么想法吗?
发布于 2022-10-27 10:30:07
您可以使用jq来解析结果,而不是grep。例如:
aws ecs list-tasks --cluster "$cluster" --region "$region"jq -r .taskArns[0]execute-command,使用xargs将管道输出作为arg:xargs aws ecs execute-command --cluster "$cluster" --region "$region" --container "$container" --command "/bin/bash" --interactive --task合在一起:
aws ecs list-tasks --cluster "$cluster" --region "$region" | \
jq -r .taskArns[0] | \
xargs aws ecs execute-command --cluster "$cluster" --region "$region" --container "$container" --command "/bin/bash" --interactive --task为了便于使用,我建议将它放入bash脚本中,但是如果您想要一个一行脚本,就可以做到这一点。
发布于 2021-07-09 19:07:23
这很难看,但起作用了
alias connect-to-app="aws ecs execute-command --cluster <cluster> --task \"$(aws ecs list-tasks --cluster <cluster> --family <family> | grep -e "arn" | grep -o '/<cluster>/\w*' | sed "s@/<cluster>/@@g")\" --container <container> --interactive --command \"/bin/bash"\"https://stackoverflow.com/questions/68320915
复制相似问题