func fetchRegion() (string, error) {
	var err error
	var region string

	config, err := appconfig.Config(false)
	if err == nil && config.Agent.ContainerMode {
		container := &containers.Container{}
		return container.Region()
	}

	// trying to get region from managed instance registration
	if region = managedInstance.Region(); region != "" {
		return region, nil
	}

	// trying to get region from metadata
	if region, err = metadata.Region(); region != "" && err == nil {
		return region, nil
	}

	// trying to get region from dynamic data
	if region, err = dynamicData.Region(); region != "" && err == nil {
		return region, nil
	}

	// return combined error messages
	return "", fmt.Errorf(errorMessage, "region", err)
}
// fetchRegion fetches the region with the following preference order.
// 1. managed instance registration
// 2. EC2 Instance Metadata
// 3. EC2 Instance Dynamic Data
fetchRegion fetches the region with the following preference order.
1. managed instance registration
2. EC2 Instance Metadata
3. EC2 Instance Dynamic Data
// fetchRegion fetches the region with the following preference order . // 1 . managed instance registration // 2 . EC2 Instance Metadata // 3 . EC2 Instance Dynamic Data
func fetchRegion() (string, error) {
	var err error
	var region string
	config, err := appconfig.Config(false)
	if err == nil && config.Agent.ContainerMode {
		container := &containers.Container{}
		return container.Region()
	}
	if region = managedInstance.Region(); region != "" {
		return region, nil
	}
	if region, err = metadata.Region(); region != "" && err == nil {
		return region, nil
	}
	if region, err = dynamicData.Region(); region != "" && err == nil {
		return region, nil
	}
	return "", fmt.Errorf(errorMessage, "region", err)
}
func fetchRegion ( ) ( string , error ) { var err error var region string config , err := appconfig . Config ( false ) if err == nil && config . Agent . ContainerMode { container := & containers . Container { } return container . Region ( ) } if region = managedInstance . Region ( ) ; region != " " { return region , nil } if region , err = metadata . Region ( ) ; region != " " && err == nil { return region , nil } if region , err = dynamicData . Region ( ) ; region != " " && err == nil { return region , nil } return " " , fmt . Errorf ( errorMessage , " " , err ) }
fetchRegion fetches the region with the following preference order.
fetchRegion fetches the region with the following preference order .
// trying to get region from managed instance registration // trying to get region from metadata // trying to get region from dynamic data // return combined error messages