本文整理匯總了Golang中github.com/aws/aws-sdk-go/service/ec2.EC2.StopInstances方法的典型用法代碼示例。如果您正苦於以下問題:Golang EC2.StopInstances方法的具體用法?Golang EC2.StopInstances怎麽用?Golang EC2.StopInstances使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/aws/aws-sdk-go/service/ec2.EC2
的用法示例。
在下文中一共展示了EC2.StopInstances方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: StopInstances
func StopInstances(cmd *cobra.Command, args []string) (resp map[string]*ec2.StopInstancesOutput, err error) {
var (
dryrun bool
data map[string]*ec2.DescribeInstancesOutput
svc *ec2.EC2
r *ec2.StopInstancesOutput
)
resp = make(map[string]*ec2.StopInstancesOutput)
dryrun, _ = cmd.Flags().GetBool("dryrun")
data, err = GetEC2Instances(cmd, args)
if err == nil {
for region, _ := range data {
var instanceIds []*string
svc = ec2.New(session.New(), &aws.Config{Region: aws.String(region)})
for idx, _ := range data[region].Reservations {
for _, inst := range data[region].Reservations[idx].Instances {
if !IsTagged(inst) && IsRunning(inst) {
if IsSpot(inst) {
log.Printf("Can not stop spot instance: %s", *inst.InstanceId)
continue
}
instanceIds = append(instanceIds, inst.InstanceId)
}
}
}
if len(instanceIds) > 0 {
params := &ec2.StopInstancesInput{
InstanceIds: instanceIds,
DryRun: aws.Bool(dryrun),
}
r, err = svc.StopInstances(params)
if err != nil {
fmt.Println("OMG")
fmt.Println(r.StoppingInstances)
fmt.Println("OMG")
resp[region] = r
}
}
}
}
return
}