当前位置: 首页>>代码示例>>Golang>>正文


Golang CloudFormation.DescribeStackResources方法代码示例

本文整理汇总了Golang中github.com/aws/aws-sdk-go/service/cloudformation.CloudFormation.DescribeStackResources方法的典型用法代码示例。如果您正苦于以下问题:Golang CloudFormation.DescribeStackResources方法的具体用法?Golang CloudFormation.DescribeStackResources怎么用?Golang CloudFormation.DescribeStackResources使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/aws/aws-sdk-go/service/cloudformation.CloudFormation的用法示例。


在下文中一共展示了CloudFormation.DescribeStackResources方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: describeRackStacks

// describeRackStacks uses credentials to describe CF service, app and rack stacks that belong to the rack name and region
func describeRackStacks(rackName, distinctId string, CF *cloudformation.CloudFormation) (Stacks, error) {
	res, err := CF.DescribeStacks(&cloudformation.DescribeStacksInput{})
	if err != nil {
		return Stacks{}, err
	}

	apps := []Stack{}
	rack := []Stack{}
	services := []Stack{}

	for _, stack := range res.Stacks {
		events := map[string]string{}
		outputs := map[string]string{}
		tags := map[string]string{}

		for _, output := range stack.Outputs {
			outputs[*output.OutputKey] = *output.OutputValue
		}

		for _, tag := range stack.Tags {
			tags[*tag.Key] = *tag.Value
		}

		name := tags["Name"]
		if name == "" {
			name = *stack.StackName
		}

		buckets := []string{}

		rres, err := CF.DescribeStackResources(&cloudformation.DescribeStackResourcesInput{
			StackName: stack.StackId,
		})
		if err != nil {
			return Stacks{}, err
		}

		for _, resource := range rres.StackResources {
			if *resource.ResourceType == "AWS::S3::Bucket" {
				if resource.PhysicalResourceId != nil {
					buckets = append(buckets, *resource.PhysicalResourceId)
				}
			}
		}

		eres, err := CF.DescribeStackEvents(&cloudformation.DescribeStackEventsInput{
			StackName: stack.StackId,
		})
		if err != nil {
			return Stacks{}, err
		}

		for _, event := range eres.StackEvents {
			if strings.HasSuffix(*event.ResourceStatus, "FAILED") {
				events[*event.LogicalResourceId] = *event.ResourceStatusReason
			}
		}

		s := Stack{
			Name:      name,
			StackName: *stack.StackName,
			Status:    *stack.StackStatus,
			Type:      tags["Type"],

			Buckets: buckets,
			Events:  events,
			Outputs: outputs,
		}

		// collect stacks that are explicitly related to the rack
		if tags["Rack"] == rackName {
			switch tags["Type"] {
			case "app":
				apps = append(apps, s)
			case "service":
				services = append(services, s)
			}
		}

		// collect stack that is explicitly the rack
		if *stack.StackName == rackName && outputs["Dashboard"] != "" {
			rack = append(rack, s)
		}
	}

	return Stacks{
		Apps:     apps,
		Rack:     rack,
		Services: services,
	}, nil
}
开发者ID:convox,项目名称:rack,代码行数:92,代码来源:uninstall.go


注:本文中的github.com/aws/aws-sdk-go/service/cloudformation.CloudFormation.DescribeStackResources方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。