From e26937a951d0f753c732fb69a7705345c7289a0e Mon Sep 17 00:00:00 2001 From: k1LoW Date: Fri, 3 Nov 2023 17:13:34 +0900 Subject: [PATCH] Identify the region of the bucket Fix #298 --- datastore/datastore.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/datastore/datastore.go b/datastore/datastore.go index 8f47ab87..d7e4012a 100644 --- a/datastore/datastore.go +++ b/datastore/datastore.go @@ -10,8 +10,10 @@ import ( "cloud.google.com/go/bigquery" "cloud.google.com/go/storage" + "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/s3" + "github.com/aws/aws-sdk-go/service/s3/s3manager" "github.com/k1LoW/octocov/datastore/artifact" "github.com/k1LoW/octocov/datastore/bq" "github.com/k1LoW/octocov/datastore/gcs" @@ -97,7 +99,18 @@ func New(ctx context.Context, u string, hints ...HintFunc) (Datastore, error) { case S3: bucket := args[0] prefix := args[1] - sess, err := session.NewSession() + region, err := s3manager.GetBucketRegion( + ctx, + session.Must(session.NewSession()), + bucket, + "us-east-1", + ) + if err != nil { + return nil, err + } + sess, err := session.NewSession(&aws.Config{ + Region: aws.String(region), + }) if err != nil { return nil, err }