Getting Outputs from aws cloudformation describe-stacks

99封情书 提交于 2019-11-28 20:08:01
Steven Yong

I got the answer, use the below:

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

Hope this will help someone.

While querying works, it may prove problematic if you have multiple stacks. Realistically, you should probably be leveraging exports for things that are distinct and authoritative.

By way of example - if you modified your CloudFormation snippet to look like this:

"Outputs" : {
  "DbUrl" : {
    "Description" : "My Database Url",
    "Value" : "myUrl",
    "Export" : {
      "Name" : "DbUrl"
    }
  }
}

Then you could use:

aws cloudformation list-exports --query "Exports[?Name==\`DbUrl\`].Value" --no-paginate --output text

to retrieve it. Exports are required to be unique - only one stack can export any given name. This way, you're assured that you get the right value, every time. If you attempt to create a new stack that exports a name that already exists elsewhere, that stack creation will fail.

Using the Windows AWS CLI I had to ensure the --query param was doubled quoted.

aws cloudformation describe-stacks --stack-name <stack_name> --query "Stacks[0].Outputs[?OutputKey==`<key_we_want>`].OutputValue" --output text

Failing to use double quotes, resulted in the query returning:

Stacks[0].Outputs[?OutputKey==].OutputValue

Not so helpful.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!