Skip to content

Commit ae243f2

Browse files
authored
Allow Specify AWS Region (#1184)
1 parent dfa7a88 commit ae243f2

File tree

6 files changed

+16
-2
lines changed

6 files changed

+16
-2
lines changed

Diff for: clients/iceberg/staging.go

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ func (s Store) uploadToS3(ctx context.Context, fp string) (string, error) {
3737
FilePath: fp,
3838
OverrideAWSAccessKeyID: s.config.Iceberg.S3Tables.AwsAccessKeyID,
3939
OverrideAWSAccessKeySecret: s.config.Iceberg.S3Tables.AwsSecretAccessKey,
40+
Region: s.config.Iceberg.S3Tables.Region,
4041
})
4142

4243
if err != nil {

Diff for: clients/redshift/redshift.go

+7
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,13 @@ func LoadRedshift(ctx context.Context, cfg config.Config, _store *db.Store) (*St
140140
Store: store,
141141
}
142142

143+
// TODO: Move this and the lower required env into a separate function
144+
for _, requiredEnv := range []string{"AWS_REGION"} {
145+
if os.Getenv(requiredEnv) == "" {
146+
return nil, fmt.Errorf("required environment variable %q is not set", requiredEnv)
147+
}
148+
}
149+
143150
if cfg.Redshift.RoleARN != "" {
144151
for _, requiredEnv := range []string{"AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY"} {
145152
if os.Getenv(requiredEnv) == "" {

Diff for: clients/redshift/staging.go

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ func (s *Store) PrepareTemporaryTable(ctx context.Context, tableData *optimizati
5454
OptionalS3Prefix: s.optionalS3Prefix,
5555
Bucket: s.bucket,
5656
FilePath: fp,
57+
Region: os.Getenv("AWS_REGION"),
5758
}
5859

5960
if s._awsCredentials != nil {

Diff for: clients/s3/s3.go

+1
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ func (s *Store) Merge(ctx context.Context, tableData *optimization.TableData) (b
135135
FilePath: fp,
136136
OverrideAWSAccessKeyID: s.config.S3.AwsAccessKeyID,
137137
OverrideAWSAccessKeySecret: s.config.S3.AwsSecretAccessKey,
138+
Region: s.config.S3.AwsRegion,
138139
}); err != nil {
139140
return false, fmt.Errorf("failed to upload file to s3: %w", err)
140141
}

Diff for: lib/awslib/s3.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package awslib
22

33
import (
4+
"cmp"
45
"context"
56
"fmt"
67
"os"
@@ -19,6 +20,7 @@ type UploadArgs struct {
1920
OverrideAWSAccessKeyID string
2021
OverrideAWSAccessKeySecret string
2122
OverrideAWSSessionToken string
23+
Region string
2224
}
2325

2426
// UploadLocalFileToS3 - takes a filepath with the file and bucket and optional expiry
@@ -27,11 +29,12 @@ func UploadLocalFileToS3(ctx context.Context, args UploadArgs) (string, error) {
2729
var cfg aws.Config
2830
var err error
2931

32+
awsRegion := cmp.Or(args.Region, os.Getenv("AWS_REGION"))
3033
if args.OverrideAWSAccessKeyID != "" && args.OverrideAWSAccessKeySecret != "" {
3134
creds := credentials.NewStaticCredentialsProvider(args.OverrideAWSAccessKeyID, args.OverrideAWSAccessKeySecret, args.OverrideAWSSessionToken)
32-
cfg, err = config.LoadDefaultConfig(ctx, config.WithCredentialsProvider(creds))
35+
cfg, err = config.LoadDefaultConfig(ctx, config.WithCredentialsProvider(creds), config.WithRegion(awsRegion))
3336
} else {
34-
cfg, err = config.LoadDefaultConfig(ctx)
37+
cfg, err = config.LoadDefaultConfig(ctx, config.WithRegion(awsRegion))
3538
}
3639

3740
if err != nil {

Diff for: lib/config/destination_types.go

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ type S3Settings struct {
5050
Bucket string `yaml:"bucket"`
5151
AwsAccessKeyID string `yaml:"awsAccessKeyID"`
5252
AwsSecretAccessKey string `yaml:"awsSecretAccessKey"`
53+
AwsRegion string `yaml:"awsRegion"`
5354
OutputFormat constants.S3OutputFormat `yaml:"outputFormat"`
5455
}
5556

0 commit comments

Comments
 (0)