예제 #1
0
func GetClusterMembersByFunc(findAutoscalingGroup func(string) (*autoscaling.Group, error)) (map[string]string, error) {
	// Availability Zone
	availabilityZone, err := util.HttpGet("http://169.254.169.254/latest/meta-data/placement/availability-zone")
	if err != nil {
		return nil, err
	}

	// Region
	region := availabilityZone[:len(availabilityZone)-1]

	// Find which is the autoscaling group
	autoscalingGroup, err := findAutoscalingGroup(region)
	if err != nil {
		return nil, err
	}

	// Create list of instance identifiers
	instanceIds := make([]*string, 0)
	for _, i := range autoscalingGroup.Instances {
		instanceIds = append(instanceIds, i.InstanceID)
	}

	// Find EC2 instance properties
	privateAddresses, err := findEC2InstancesPrivateAddresses(instanceIds, region)
	if err != nil {
		return nil, err
	}

	return privateAddresses, nil
}
예제 #2
0
func (aws *Aws) GetInstancePrivateAddress() (string, error) {
	// Local IPv4 (Private Address)
	localIp, err := util.HttpGet("http://169.254.169.254/latest/meta-data/local-ipv4")
	if err != nil {
		return "", err
	}

	return localIp, nil
}
예제 #3
0
func (aws *Aws) GetInstanceId() (string, error) {
	// Instance Id
	instanceId, err := util.HttpGet("http://169.254.169.254/latest/meta-data/instance-id")
	if err != nil {
		return "", err
	}

	return instanceId, nil
}