Skip to content

Commit

Permalink
[8.16](backport #41572) [aws] Set region in config from GetBucketLoca…
Browse files Browse the repository at this point in the history
…tion API call (#41589)

* [aws] Set region in config from GetBucketLocation API call (#41572)

This PR sets the region of the S3 bucket as the region in AWS config to make API calls.

(cherry picked from commit 076ea50)

* Update CHANGELOG.next.asciidoc

---------

Co-authored-by: kaiyan-sheng <[email protected]>
  • Loading branch information
mergify[bot] and kaiyan-sheng authored Nov 11, 2024
1 parent dd62122 commit f0c8564
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff]
- Log bad handshake details when websocket connection fails {pull}41300[41300]
- Improve modification time handling for entities and entity deletion logic in the Active Directory entityanalytics input. {pull}41179[41179]
- Journald input now can read events from all boots {issue}41083[41083] {pull}41244[41244]
- Fix aws region in aws-s3 input s3 polling mode. {pull}41572[41572]
- Fix errors in SQS host resolution in the `aws-s3` input when using custom (non-AWS) endpoints. {pull}41504[41504]
- The azure-eventhub input now correctly reports its status to the Elastic Agent on fatal errors {pull}41469[41469]

Expand Down
12 changes: 6 additions & 6 deletions x-pack/filebeat/input/awss3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ import (
"github.com/elastic/beats/v7/libbeat/beat"
)

func createS3API(ctx context.Context, config config, awsConfig awssdk.Config) (*awsS3API, error) {
s3Client := s3.NewFromConfig(awsConfig, config.s3ConfigModifier)
regionName, err := getRegionForBucket(ctx, s3Client, config.getBucketName())
func (in *s3PollerInput) createS3API(ctx context.Context) (*awsS3API, error) {
s3Client := s3.NewFromConfig(in.awsConfig, in.config.s3ConfigModifier)
regionName, err := getRegionForBucket(ctx, s3Client, in.config.getBucketName())
if err != nil {
return nil, fmt.Errorf("failed to get AWS region for bucket: %w", err)
}
// Can this really happen?
if regionName != awsConfig.Region {
awsConfig.Region = regionName
s3Client = s3.NewFromConfig(awsConfig, config.s3ConfigModifier)
if regionName != in.awsConfig.Region {
in.awsConfig.Region = regionName
s3Client = s3.NewFromConfig(in.awsConfig, in.config.s3ConfigModifier)
}

return newAWSs3API(s3Client), nil
Expand Down
2 changes: 1 addition & 1 deletion x-pack/filebeat/input/awss3/s3_input.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (in *s3PollerInput) Run(
defer in.states.Close()

ctx := v2.GoContextFromCanceler(inputContext.Cancelation)
in.s3, err = createS3API(ctx, in.config, in.awsConfig)
in.s3, err = in.createS3API(ctx)
if err != nil {
return fmt.Errorf("failed to create S3 API: %w", err)
}
Expand Down

0 comments on commit f0c8564

Please sign in to comment.