Skip to content

Commit

Permalink
[MetricBeat] add param aws_partition to support aws-cn, aws-us-gov …
Browse files Browse the repository at this point in the history
…regions (elastic#19423)

* add params `aws_partition` to support other aws region: aws-cn, aws-us-gov
  • Loading branch information
kwinstonix authored and melchiormoulin committed Oct 14, 2020
1 parent f736ef9 commit 21dea57
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Fix incorrect usage of hints builder when exposed port is a substring of the hint {pull}19052[19052]
- Remove dedot for tag values in aws module. {issue}19112[19112] {pull}19221[19221]
- Stop counterCache only when already started {pull}19103[19103]
- Add param `aws_partition` to support aws-cn, aws-us-gov regions. {issue}18850[18850] {pull}19423[19423]
- Fix bug incorrect parsing of float numbers as integers in Couchbase module {issue}18949[18949] {pull}19055[19055]

*Packetbeat*
Expand Down
1 change: 1 addition & 0 deletions x-pack/libbeat/common/aws/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type ConfigAWS struct {
SharedCredentialFile string `config:"shared_credential_file"`
Endpoint string `config:"endpoint"`
RoleArn string `config:"role_arn"`
AWSPartition string `config:"aws_partition"`
}

// GetAWSCredentials function gets aws credentials from the config.
Expand Down
1 change: 1 addition & 0 deletions x-pack/libbeat/docs/aws-credentials-config.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ To configure AWS credentials, either put the credentials into the {beatname_uc}
* *shared_credential_file*: directory of the shared credentials file.
* *endpoint*: URL of the entry point for an AWS web service.
* *role_arn*: AWS IAM Role to assume.
* *aws_partition*: AWS region parttion name, value is one of `aws, aws-cn, aws-us-gov`, default is `aws`.

[float]
==== Supported Formats
Expand Down
12 changes: 10 additions & 2 deletions x-pack/metricbeat/module/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,16 @@ func NewMetricSet(base mb.BaseMetricSet) (*MetricSet, error) {
base.Logger().Debug("Metricset level config for period: ", metricSet.Period)
base.Logger().Debug("Metricset level config for tags filter: ", metricSet.TagsFilter)

// Get IAM account name
awsConfig.Region = "us-east-1"
// Get IAM account name, set region by aws_partition, default is aws global partition
// refer https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html
switch config.AWSConfig.AWSPartition {
case "aws-cn":
awsConfig.Region = "cn-north-1"
case "aws-us-gov":
awsConfig.Region = "us-gov-east-1"
default:
awsConfig.Region = "us-east-1"
}
svcIam := iam.New(awscommon.EnrichAWSConfigWithEndpoint(
config.AWSConfig.Endpoint, "iam", "", awsConfig))
req := svcIam.ListAccountAliasesRequest(&iam.ListAccountAliasesInput{})
Expand Down

0 comments on commit 21dea57

Please sign in to comment.