Getting Outputs from aws cloudformation describe-stacks

I got the answer, use the below:

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

Or

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

Or

--query 'Stacks[?StackName=='mystack'][].Outputs[?OutputKey==`DbUrl`].OutputValue' --output text

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.