Getting Outputs from aws cloudformation describe-stacks

后端 未结 3 1424
慢半拍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条回答
  •  -上瘾入骨i
    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.

提交回复
热议问题