AWS 文档 SDK 示例
将 DescribeStacks 与 AWS SDK 或 CLI 配合使用
以下代码示例演示如何使用 DescribeStacks。
- CLI
-
- AWS CLI
-
描述 AWS CloudFormation 堆栈
以下
describe-stacks命令显示myteststack堆栈的摘要信息:aws cloudformation describe-stacks --stack-namemyteststack输出:
{ "Stacks": [ { "StackId": "arn:aws:cloudformation:us-east-1:123456789012:stack/myteststack/466df9e0-0dff-08e3-8e2f-5088487c4896", "Description": "AWS CloudFormation Sample Template S3_Bucket: Sample template showing how to create a publicly accessible S3 bucket. **WARNING** This template creates an S3 bucket. You will be billed for the AWS resources used if you create a stack from this template.", "Tags": [], "Outputs": [ { "Description": "Name of S3 bucket to hold website content", "OutputKey": "BucketName", "OutputValue": "myteststack-s3bucket-jssofi1zie2w" } ], "StackStatusReason": null, "CreationTime": "2013-08-23T01:02:15.422Z", "Capabilities": [], "StackName": "myteststack", "StackStatus": "CREATE_COMPLETE", "DisableRollback": false } ] }有关更多信息,请参阅《AWS CloudFormation 用户指南》中的“堆栈”。
-
有关 API 详细信息,请参阅《AWS CLI 命令参考》中的 DescribeStacks
。
-
- Go
-
- 适用于 Go V2 的 SDK
-
注意
查看 GitHub,了解更多信息。在 AWS 代码示例存储库
中查找完整示例,了解如何进行设置和运行。 import ( "context" "log" "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/cloudformation" ) // StackOutputs defines a map of outputs from a specific stack. type StackOutputs map[string]string type CloudFormationActions struct { CfnClient *cloudformation.Client } // GetOutputs gets the outputs from a CloudFormation stack and puts them into a structured format. func (actor CloudFormationActions) GetOutputs(ctx context.Context, stackName string) StackOutputs { output, err := actor.CfnClient.DescribeStacks(ctx, &cloudformation.DescribeStacksInput{ StackName: aws.String(stackName), }) if err != nil || len(output.Stacks) == 0 { log.Panicf("Couldn't find a CloudFormation stack named %v. Here's why: %v\n", stackName, err) } stackOutputs := StackOutputs{} for _, out := range output.Stacks[0].Outputs { stackOutputs[*out.OutputKey] = *out.OutputValue } return stackOutputs }-
有关 API 详细信息,请参阅《适用于 Go 的 AWS SDK API Reference》中的 DescribeStacks
。
-
- PowerShell
-
- Tools for PowerShell V4
-
示例 1:返回描述用户的所有堆栈的堆栈实例集合。
Get-CFNStack示例 2:返回描述指定堆栈的堆栈实例
Get-CFNStack -StackName "myStack"-
有关 API 详细信息,请参阅《AWS Tools for PowerShell Cmdlet Reference(V4)》中的 DescribeStacks。
-
- Tools for PowerShell V5
-
示例 1:返回描述用户的所有堆栈的堆栈实例集合。
Get-CFNStack示例 2:返回描述指定堆栈的堆栈实例
Get-CFNStack -StackName "myStack"-
有关 API 详细信息,请参阅《AWS Tools for PowerShell Cmdlet Reference(V5)》中的 DescribeStacks。
-
DescribeStackResources
EstimateTemplateCost