本文整理汇总了Golang中github.com/aws/aws-sdk-go/service/ec2.EC2.DescribeInstancesPages方法的典型用法代码示例。如果您正苦于以下问题:Golang EC2.DescribeInstancesPages方法的具体用法?Golang EC2.DescribeInstancesPages怎么用?Golang EC2.DescribeInstancesPages使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/aws/aws-sdk-go/service/ec2.EC2
的用法示例。
在下文中一共展示了EC2.DescribeInstancesPages方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: getInstancesWithTag
func getInstancesWithTag(ec2Client *ec2.EC2, key string, value string) ([]*ec2.Instance, error) {
var instances []*ec2.Instance
err := ec2Client.DescribeInstancesPages(&ec2.DescribeInstancesInput{
Filters: []*ec2.Filter{
&ec2.Filter{
Name: aws.String("instance-state-name"),
Values: []*string{aws.String("running")},
},
&ec2.Filter{
Name: aws.String(fmt.Sprintf("tag:%s", key)),
Values: []*string{aws.String(value)},
},
},
}, func(result *ec2.DescribeInstancesOutput, _ bool) bool {
for _, reservation := range result.Reservations {
instances = append(instances, reservation.Instances...)
}
return true // keep going
})
if err != nil {
return nil, err
}
return instances, nil
}
示例2: processInstances
func processInstances(svc *ec2.EC2, pageSize *int64, apply func([]*string)) {
err := svc.DescribeInstancesPages(&ec2.DescribeInstancesInput{
MaxResults: pageSize,
},
func(instancesOut *ec2.DescribeInstancesOutput, lastPage bool) bool {
var instanceIds []*string
for idx := range instancesOut.Reservations {
for _, instance := range instancesOut.Reservations[idx].Instances {
instanceIds = append(instanceIds, instance.InstanceId)
}
}
apply(instanceIds)
return !lastPage
})
kingpin.FatalIfError(err, "Could not retrieve EC2 instances")
}