Skip to content

Commit

Permalink
Merge pull request #12 from FindHotel/ch32357-inject-aws-session-to-N…
Browse files Browse the repository at this point in the history
…ewS3ClientWithConfig

Add support to pass aws session to the s3 client factory method
  • Loading branch information
xesina authored Apr 15, 2021
2 parents 4300fec + 6fc6873 commit 7e7760a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 3 additions & 2 deletions s3client.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ type S3 struct {
KeyConstructor func(now func() Time, uid func() string) string

UploaderOptions []func(*s3manager.Uploader)

Session *session.Session
}

// S3ClientConfig provides configuration for S3 Client.
Expand All @@ -75,8 +77,7 @@ func NewS3ClientWithConfig(config S3ClientConfig) (Client, error) {

client.msgs = make(chan Message, 1024) // overrite the buffer

sess := session.Must(session.NewSession())
uploader := s3manager.NewUploader(sess, cfg.S3.UploaderOptions...)
uploader := s3manager.NewUploader(cfg.S3.Session, cfg.S3.UploaderOptions...)

c := &s3Client{
client: client,
Expand Down
9 changes: 9 additions & 0 deletions s3clientconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package analytics

import (
"fmt"
"github.com/aws/aws-sdk-go/aws/session"
"strings"
"time"
)
Expand Down Expand Up @@ -50,5 +51,13 @@ func makeS3ClientConfig(c S3ClientConfig) (S3ClientConfig, error) {
}
}

if c.S3.Session == nil {
var err error
c.S3.Session, err = session.NewSession()
if err != nil {
return c, fmt.Errorf("analytics: creating s3 client session failed: %w", err)
}
}

return c, nil
}

0 comments on commit 7e7760a

Please sign in to comment.