func NewService(log log.T, mgsConfig appconfig.MgsConfig, connectionTimeout time.Duration) Service {

	var region *string
	if mgsConfig.Region != "" {
		region = aws.String(mgsConfig.Region)
	} else {
		fetchedRegion, err := platform.Region()
		if err != nil {
			log.Errorf("Failed to get region with error: %s", err)
		}
		region = &fetchedRegion
	}

	log.Debug("Getting credentials for v4 signatures.")
	var v4Signer *v4.Signer
	creds, _ := getCredentials()
	if creds != nil {
		v4Signer = v4.NewSigner(creds)
	} else {
		config, _ := appconfig.Config(false)
		if config.Agent.ContainerMode {
			log.Debug("Getting credentials for v4 signatures from the task role credentials.")
			config := sdkutil.AwsConfig()
			v4Signer = v4.NewSigner(config.Credentials)
		} else {
			log.Debug("Getting credentials for v4 signatures from the metadata service.")

			// load from the metadata service
			metadataCreds := ec2rolecreds.NewCredentials(session.New())
			if metadataCreds != nil {
				v4Signer = v4.NewSigner(metadataCreds)
			} else {
				log.Debug("Failed to get the creds from the metadata service.")
			}
		}
	}

	// capture Transport so we can use it to cancel requests
	tr := &http.Transport{
		Proxy: http.ProxyFromEnvironment,
		Dial: (&net.Dialer{
			Timeout:   connectionTimeout,
			KeepAlive: 0,
		}).Dial,
		TLSHandshakeTimeout: 10 * time.Second,
	}

	return &MessageGatewayService{
		region: aws.StringValue(region),
		tr:     tr,
		signer: v4Signer,
	}
}
// NewService creates a new service instance.
NewService creates a new service instance.
// NewService creates a new service instance .
func NewService(log log.T, mgsConfig appconfig.MgsConfig, connectionTimeout time.Duration) Service {
	var region *string
	if mgsConfig.Region != "" {
		region = aws.String(mgsConfig.Region)
	} else {
		fetchedRegion, err := platform.Region()
		if err != nil {
			log.Errorf("Failed to get region with error: %s", err)
		}
		region = &fetchedRegion
	}
	log.Debug("Getting credentials for v4 signatures.")
	var v4Signer *v4.Signer
	creds, _ := getCredentials()
	if creds != nil {
		v4Signer = v4.NewSigner(creds)
	} else {
		config, _ := appconfig.Config(false)
		if config.Agent.ContainerMode {
			log.Debug("Getting credentials for v4 signatures from the task role credentials.")
			config := sdkutil.AwsConfig()
			v4Signer = v4.NewSigner(config.Credentials)
		} else {
			log.Debug("Getting credentials for v4 signatures from the metadata service.")
			metadataCreds := ec2rolecreds.NewCredentials(session.New())
			if metadataCreds != nil {
				v4Signer = v4.NewSigner(metadataCreds)
			} else {
				log.Debug("Failed to get the creds from the metadata service.")
			}
		}
	}
	tr := &http.Transport{
		Proxy: http.ProxyFromEnvironment,
		Dial: (&net.Dialer{
			Timeout:   connectionTimeout,
			KeepAlive: 0,
		}).Dial,
		TLSHandshakeTimeout: 10 * time.Second,
	}
	return &MessageGatewayService{
		region: aws.StringValue(region),
		tr:     tr,
		signer: v4Signer,
	}
}
func NewService ( log log . T , mgsConfig appconfig . MgsConfig , connectionTimeout time . Duration ) Service { var region * string if mgsConfig . Region != " " { region = aws . String ( mgsConfig . Region ) } else { fetchedRegion , err := platform . Region ( ) if err != nil { log . Errorf ( " " , err ) } region = & fetchedRegion } log . Debug ( " " ) var v4Signer * v4 . Signer creds , _ := getCredentials ( ) if creds != nil { v4Signer = v4 . NewSigner ( creds ) } else { config , _ := appconfig . Config ( false ) if config . Agent . ContainerMode { log . Debug ( " " ) config := sdkutil . AwsConfig ( ) v4Signer = v4 . NewSigner ( config . Credentials ) } else { log . Debug ( " " ) metadataCreds := ec2rolecreds . NewCredentials ( session . New ( ) ) if metadataCreds != nil { v4Signer = v4 . NewSigner ( metadataCreds ) } else { log . Debug ( " " ) } } } tr := & http . Transport { Proxy : http . ProxyFromEnvironment , Dial : ( & net . Dialer { Timeout : connectionTimeout , KeepAlive : 0 , } ) . Dial , TLSHandshakeTimeout : 10 * time . Second , } return & MessageGatewayService { region : aws . StringValue ( region ) , tr : tr , signer : v4Signer , } }
NewService creates a new service instance.
NewService creates a new service instance .
// load from the metadata service // capture Transport so we can use it to cancel requests