當前位置: 首頁>>代碼示例>>Golang>>正文


Golang ECS.ListContainerInstances方法代碼示例

本文整理匯總了Golang中github.com/aws/aws-sdk-go/service/ecs.ECS.ListContainerInstances方法的典型用法代碼示例。如果您正苦於以下問題:Golang ECS.ListContainerInstances方法的具體用法?Golang ECS.ListContainerInstances怎麽用?Golang ECS.ListContainerInstances使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/aws/aws-sdk-go/service/ecs.ECS的用法示例。


在下文中一共展示了ECS.ListContainerInstances方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: GetContainerInstances

// GetContainerInstances will return a slice of ECS Container Instances within a cluster
func GetContainerInstances(svc *ecs.ECS, ec2svc *ec2.EC2, cluster *string) (containerInstances []*ecs.ContainerInstance, instances []*ec2.Reservation, e error) {

	var ciArns []*string

	// List clusters
	reqParams := &ecs.ListContainerInstancesInput{
		Cluster:    cluster,
		MaxResults: aws.Int64(100),
		NextToken:  aws.String(""),
	}

	// Loop through tokens until no more results remain
	for {
		resp, err := svc.ListContainerInstances(reqParams)

		// Error check
		if err != nil {
			return nil, nil, fmt.Errorf("ecs.ListContainerInstances: %s", err.Error())
		}

		// Expand slice of container instances and append to our comprehensive list
		ciArns = append(ciArns, resp.ContainerInstanceArns...)

		// Cycle token
		if resp.NextToken != nil {
			reqParams.NextToken = resp.NextToken
		} else {
			// Kill loop ... out of response pages
			break
		}

	}

	// Describe the tasks that we just got back
	ciResponse, err := svc.DescribeContainerInstances(&ecs.DescribeContainerInstancesInput{
		Cluster:            cluster,
		ContainerInstances: ciArns,
	})

	if err != nil {
		return nil, nil, fmt.Errorf("ecs.DescribeContainerInstances: %s", err.Error())
	}

	var instanceIds []*string
	for _, k := range ciResponse.ContainerInstances {
		instanceIds = append(instanceIds, k.Ec2InstanceId)
	}

	// Create a map of container instances by ci arn...
	// Note: Will work for <= 1000 instances w/o having to use NextToken
	ec2Resp, err := ec2svc.DescribeInstances(&ec2.DescribeInstancesInput{
		InstanceIds: instanceIds,
	})

	if err != nil {
		return nil, nil, fmt.Errorf("ec2.DescribeInstances: %s", err.Error())
	}

	return ciResponse.ContainerInstances, ec2Resp.Reservations, nil
}
開發者ID:colinmutter,項目名稱:go-ecs,代碼行數:61,代碼來源:ecs.go

示例2: containerInstances

func containerInstances(e *ecspkg.ECS, cluster *string) []*string {
	instances := []*string{}
	next := aws.String("")
	for next != nil {
		input := ecspkg.ListContainerInstancesInput{
			Cluster: cluster,
		}
		if next != nil && *next != "" {
			input.NextToken = next
		}
		output, err := e.ListContainerInstances(&input)
		log.Check(err)
		instances = append(instances, output.ContainerInstanceArns...)
		next = output.NextToken
	}
	return instances
}
開發者ID:travisjeffery,項目名稱:ecs-exec,代碼行數:17,代碼來源:exec.go


注:本文中的github.com/aws/aws-sdk-go/service/ecs.ECS.ListContainerInstances方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。