Getting Outputs from aws cloudformation describe-stacks

后端 未结 3 1411
慢半拍i
慢半拍i 2020-12-13 08:47

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
         


        
相关标签:
3条回答
  • 2020-12-13 08:56

    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.

    0 讨论(0)
  • 2020-12-13 09:06

    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.

    0 讨论(0)
  • 2020-12-13 09:08

    I got the answer, use the below:

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

    Hope this will help someone.

    0 讨论(0)
提交回复
热议问题