Fix AWS config

This commit is contained in:
Leonid Bugaev
2017-04-29 11:39:01 +02:00
parent 2104bec5be
commit 2b6203c110
2 changed files with 18 additions and 14 deletions
+17 -2
View File
@@ -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)
+1 -12
View File
@@ -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())
}
}