在python脚本中我有aws-cli命令来打印ec2信息
def ec2Output = sh(returnStdout: true, script: "aws ec2 describe-instances --region ${Region} --filters Name=tag:Environment,Values=${Environment} --query 'Reservations[].Instances[].[Tags[?Key==`Version`].Value|[0],InstanceId]'")
echo "${ec2Output}"
然后我从上面的命令得到以下输出
[
[
"2023_v1",
"i-0xxxxxxxxxx"
"Dev"
],
[
"2023_v2",
"i-0xxxxxxxxxx"
"Dev"
],
[
"2023_v2",
"i-xxxxxxxxxx"
"Prod"
]
]
问题是,是否可以将输出转换为类似以下的预期结果:
{
"Dev":{
"Release": "2023",
"Version": "v1",
"ID": "i-0xxxxxxxxxx"
},
"Dev":{
"Release": "2023",
"Version": "v2",
"ID": "i-0xxxxxxxxxx"
},
"Prod":{
"Release": "2023",
"Version": "v2",
"ID": "i-xxxxxxxxxx"
}
}
1条答案
按热度按时间kyxcudwk1#
与其使用Python“调用”AWS CLI命令,不如使用boto3 library直接进行API调用: