aws cloudformation --region ap-southeast-2 describe-stacks --stack-name mystack
它返回了结果OK:
{
"Stacks": [
{
"StackId": "arn:aws:mystackid",
"LastUpdatedTime": "2017-01-13T04:59:17.472Z",
"Tags": [],
"Outputs": [
{
"OutputKey": "Ec2Sg",
"OutputValue": "sg-97e13dff"
},
{
"OutputKey": "DbUrl",
"OutputValue": "myUrl"
}
],
"CreationTime": "2017-01-13T03:27:18.893Z",
"StackName": "mystack",
"NotificationARNs": [],
"StackStatus": "UPDATE_ROLLBACK_COMPLETE",
"DisableRollback": false
}
]
}
但我不知道如何仅返回OutputValue的值,即我的URL。
因为我只需要这个值,而不是其他的。
通过aws cloudformation describe-stacks,这是否可能?
编辑
我刚意识到我可以使用--query:
--query "Stacks[0].Outputs[1].OutputValue"
我希望得到我想要的东西,但是如果输出的数量发生变化,我希望使用DbUrl,否则我的结果会出乎意料。
"
而不是单引号'
。 - Tobin`--query 'Stacks[0].Outputs[?OutputKey==\`ParamOne\` || OutputKey==\`ParamTwo\` || OutputKey==\`ParamThree\`].OutputValue' --output text`
- Koka--query 'Stacks[0].Outputs[?OutputKey==\
ParamOne` || OutputKey==`ParamTwo` || OutputKey==`ParamThree`]' >> params.txt; one=$(cat params.txt | jq -r '.[] | select(.OutputKey=="ParamOne") | .OutputValue'); two=$(cat params.txt | jq -r '.[] | select(.OutputKey=="ParamTwo") | .OutputValue'); three=$(cat params.txt | jq -r '.[] | select(.OutputKey=="ParamThree") | .OutputValue')` - Koka{"Ec2Sg": "sg-97e13dff", "DbUrl": "myUrl"}
。按名称获取值比按索引获取值要好得多。 - Andy