Skip to content

Commit

Permalink
Set default region to make initial aws api call
Browse files Browse the repository at this point in the history
  • Loading branch information
kaiyan-sheng committed Apr 30, 2021
1 parent d62f0a2 commit 5ff9330
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 0 additions & 2 deletions x-pack/libbeat/autodiscover/providers/aws/elb/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
14 changes: 10 additions & 4 deletions x-pack/libbeat/common/aws/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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
}
}

Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 5ff9330

Please sign in to comment.