Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
766 views
in Technique[技术] by (71.8m points)

aws cli - Getting Outputs from aws cloudformation describe-stacks

I am using the below to get the stack information I want via AWS Cli:

aws cloudformation --region ap-southeast-2 describe-stacks --stack-name mystack

It's returning result 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
        }
    ]
}

But I do not know how to return only the value of OutputValue which is myUrl

As I do not need the rest, just myUrl.

Is that possible via aws cloudformation describe-stacks?

Edit

I just realize I can use --query:

--query "Stacks[0].Outputs[1].OutputValue"

will get exactly what I want but I would like to use DbUrl else if the number of Outputs changes, my result will be unexpected.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I got the answer, use the below:

--query "Stacks[0].Outputs[?OutputKey=='DbUrl'].OutputValue" --output text

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...