コード例 #1
0
// getAutoScalingName tries to get autoscaling name from system, first gets from
// config var, if not set then tries ec2dynamicdata service
func getAutoScalingName(conf *Config, session *awssession.Session) (string, error) {
	if conf.AutoScalingName != "" {
		return conf.AutoScalingName, nil
	}

	info, err := ec2dynamicdata.Get()
	if err != nil {
		return "", fmt.Errorf("couldn't get info. Err: %s", err.Error())
	}

	instanceID := info.InstanceID

	asg := autoscaling.New(session)

	resp, err := asg.DescribeAutoScalingInstances(
		&autoscaling.DescribeAutoScalingInstancesInput{
			InstanceIds: []*string{
				aws.String(instanceID),
			},
		},
	)
	if err != nil {
		return "", err
	}

	for _, instance := range resp.AutoScalingInstances {
		if *instance.InstanceId == instanceID {
			return *instance.AutoScalingGroupName, nil
		}
	}
	return "", errors.New("couldn't find autoscaling name")
}
コード例 #2
0
// getRegion checks if region name is given in config, if not tries to get it
// from ec2dynamicdata endpoint
func getRegion(conf *Config) (string, error) {
	if conf.Region != "" {
		return conf.Region, nil
	}

	info, err := ec2dynamicdata.Get()
	if err != nil {
		return "", fmt.Errorf("couldn't get region. Err: %s", err.Error())
	}

	if info.Region == "" {
		return "", fmt.Errorf("malformed ec2dynamicdata response: %#v", info)
	}
	return info.Region, nil
}