diff --git a/x-pack/libbeat/autodiscover/providers/aws/elb/provider.go b/x-pack/libbeat/autodiscover/providers/aws/elb/provider.go index b0617baad4da..03d76c2e7f32 100644 --- a/x-pack/libbeat/autodiscover/providers/aws/elb/provider.go +++ b/x-pack/libbeat/autodiscover/providers/aws/elb/provider.go @@ -63,8 +63,6 @@ func AutodiscoverBuilder( // Construct MetricSet with a full regions list if there is no region specified. if config.Regions == nil { - // set default region to make initial aws api call - awsCfg.Region = "us-west-1" svcEC2 := ec2.New(awscommon.EnrichAWSConfigWithEndpoint( config.AWSConfig.Endpoint, "ec2", awsCfg.Region, awsCfg)) diff --git a/x-pack/libbeat/common/aws/credentials.go b/x-pack/libbeat/common/aws/credentials.go index 5069582bc097..b01249722db2 100644 --- a/x-pack/libbeat/common/aws/credentials.go +++ b/x-pack/libbeat/common/aws/credentials.go @@ -36,12 +36,12 @@ type ConfigAWS struct { func GetAWSCredentials(config ConfigAWS) (awssdk.Config, error) { // Check if accessKeyID or secretAccessKey or sessionToken is given from configuration if config.AccessKeyID != "" || config.SecretAccessKey != "" || config.SessionToken != "" { - return getAccessKeys(config) + return getAccessKeys(config), nil } return getSharedCredentialProfile(config) } -func getAccessKeys(config ConfigAWS) (awssdk.Config, error) { +func getAccessKeys(config ConfigAWS) awssdk.Config { logger := logp.NewLogger("getAccessKeys") awsConfig := defaults.Config() awsCredentials := awssdk.Credentials{ @@ -57,13 +57,16 @@ func getAccessKeys(config ConfigAWS) (awssdk.Config, error) { Value: awsCredentials, } + // Set default region to make initial aws api call + awsConfig.Region = "us-east-1" + // Assume IAM role if iam_role config parameter is given if config.RoleArn != "" { logger.Debug("Using role arn and access keys for AWS credential") - return getRoleArn(config, awsConfig), nil + return getRoleArn(config, awsConfig) } else { logger.Debug("Using access keys for AWS credential") - return awsConfig, nil + return awsConfig } } @@ -91,6 +94,9 @@ func getSharedCredentialProfile(config ConfigAWS) (awssdk.Config, error) { return awsConfig, errors.Wrap(err, "external.LoadDefaultAWSConfig failed with shared credential profile given") } + // Set default region to make initial aws api call + awsConfig.Region = "us-east-1" + // Assume IAM role if iam_role config parameter is given if config.RoleArn != "" { logger.Debug("Using role arn and shared credential profile for AWS credential")