in pkg/conn/conn.go [150:193]
func GetAWSConfigSession(cn connAttr, c *cfg.Config, roleArn string, region string, noMetadata bool) (*aws.Config, *session.Session) {
var s *session.Session
var err error
var awsRegion string
http := getNewHTTPClient(cfg.ParameterConfigValue.Processor.MaxIdleConnPerHost, cfg.ParameterConfigValue.Processor.RequestTimeout, *c.NoVerifySSL, c.ProxyAddress)
regionEnv := os.Getenv("AWS_REGION")
if region == "" && regionEnv != "" {
awsRegion = regionEnv
log.Debugf("Fetch region %v from environment variables", awsRegion)
} else if region != "" {
awsRegion = region
log.Debugf("Fetch region %v from commandline/config file", awsRegion)
} else if !noMetadata {
awsRegion = getRegionFromECSMetadata()
if awsRegion == "" {
es := getDefaultSession()
awsRegion, err = cn.getEC2Region(es)
if err != nil {
log.Errorf("Unable to fetch region from EC2 metadata: %v\n", err)
} else {
log.Debugf("Fetch region %v from ec2 metadata", awsRegion)
}
}
} else {
es := getDefaultSession()
awsRegion = *es.Config.Region
log.Debugf("Fetched region %v from session config", awsRegion)
}
if awsRegion == "" {
log.Errorf("Cannot fetch region variable from config file, environment variables, ecs metadata, or ec2 metadata. Use local-mode to use the local session region.")
os.Exit(1)
}
s = cn.newAWSSession(roleArn, awsRegion)
config := &aws.Config{
Region: aws.String(awsRegion),
DisableParamValidation: aws.Bool(true),
MaxRetries: aws.Int(2),
Endpoint: aws.String(c.Endpoint),
HTTPClient: http,
}
return config, s
}