From 2b6203c110ca91dffd3f3c14b10d5080f549094f Mon Sep 17 00:00:00 2001 From: Leonid Bugaev Date: Sat, 29 Apr 2017 11:39:01 +0200 Subject: [PATCH] Fix AWS config --- input_file.go | 19 +++++++++++++++++-- output_s3.go | 13 +------------ 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/input_file.go b/input_file.go index e3481a2..3f5066d 100644 --- a/input_file.go +++ b/input_file.go @@ -25,13 +25,28 @@ type S3ReadCloser struct { sess *session.Session } +func awsConfig() *aws.Config { + region := os.Getenv("AWS_DEFAULT_REGION") + if region == "" { + region = "us-east-1" + } + + config := &aws.Config{Region: aws.String(region)} + + if endpoint := os.Getenv("AWS_ENDPOINT_URL"); endpoint != "" { + config.Endpoint = aws.String(endpoint) + } + + return config +} + func NewS3ReadCloser(path string) *S3ReadCloser { bucket, key := parseS3Url(path) return &S3ReadCloser{ bucket: bucket, key: key, - sess: session.New(&aws.Config{Region: aws.String("us-east-1")}), + sess: session.New(awsConfig()), } } @@ -201,7 +216,7 @@ func (i *FileInput) init() (err error) { var matches []string if strings.HasPrefix(i.path, "s3://") { - sess := session.New(&aws.Config{Region: aws.String("us-east-1")}) + sess := session.New(awsConfig()) svc := s3.New(sess) bucket, key := parseS3Url(i.path) diff --git a/output_s3.go b/output_s3.go index d8ca549..16d3d79 100644 --- a/output_s3.go +++ b/output_s3.go @@ -52,19 +52,8 @@ func NewS3Output(pathTemplate string, config *FileOutputConfig) *S3Output { } func (o *S3Output) connect() { - region := os.Getenv("AWS_REGION") - if region == "" { - region = "us-east-1" - } - - config := &aws.Config{Region: aws.String(region)} - - if endpoint := os.Getenv("AWS_ENDPOINT_URL"); endpoint != "" { - config.Endpoint = aws.String(endpoint) - } - if o.session == nil { - o.session = session.New(config) + o.session = session.New(awsConfig()) } }