forked from a3linux/go-aws-mon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
as.go
37 lines (29 loc) · 903 Bytes
/
as.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package main
import (
"errors"
"fmt"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/autoscaling"
)
func getAutoscalingGroup(instanceId string, region string) (*string, error) {
session := session.New(&aws.Config{Region: ®ion})
svc := autoscaling.New(session)
params := &autoscaling.DescribeAutoScalingInstancesInput{
InstanceIds: []*string{&instanceId},
MaxRecords: aws.Int64(1),
}
resp, err := svc.DescribeAutoScalingInstances(params)
if err != nil {
if awsErr, ok := err.(awserr.Error); ok {
return nil, fmt.Errorf("[%s] %s", awsErr.Code, awsErr.Message)
} else if err != nil {
return nil, err
}
}
if len(resp.AutoScalingInstances) == 0 {
return nil, errors.New("No autoscaling group found")
}
return resp.AutoScalingInstances[0].AutoScalingGroupName, nil
}