Skip to content

Commit

Permalink
Cherry-pick #19423 to 7.x: [MetricBeat] add param aws_partition to …
Browse files Browse the repository at this point in the history
…support aws-cn, aws-us-gov regions (#19519)

* [MetricBeat] add param `aws_partition` to support aws-cn, aws-us-gov regions (#19423)

* add params `aws_partition` to support other aws region: aws-cn, aws-us-gov

(cherry picked from commit 1ea8c84)
Co-authored-by: martin <kwinstonix@users.noreply.github.com>
  • Loading branch information
kaiyan-sheng authored Jul 1, 2020
1 parent 2d0939f commit 60ea971
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,7 @@ field. You can revert this change by configuring tags for the module and omittin
- Add dashboards for googlecloud load balancing metricset. {pull}18369[18369]
- Update Couchbase to version 6.5 {issue}18595[18595] {pull}19055[19055]
- Add support for v1 consumer API in Cloud Foundry module, use it by default. {pull}19268[19268]
- Add param `aws_partition` to support aws-cn, aws-us-gov regions. {issue}18850[18850] {pull}19423[19423]

*Packetbeat*

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ require (
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5
golang.org/x/text v0.3.2
golang.org/x/time v0.0.0-20191024005414-555d28b269f0
golang.org/x/tools v0.0.0-20200626171337-aa94e735be7f
golang.org/x/tools v0.0.0-20200630154851-b2d8b0336632
google.golang.org/api v0.15.0
google.golang.org/genproto v0.0.0-20191230161307-f3c370f40bfb
google.golang.org/grpc v1.29.1
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 60ea971

Please sign in to comment.