-
Notifications
You must be signed in to change notification settings - Fork 1
/
s3_client.go
33 lines (28 loc) · 869 Bytes
/
s3_client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package kanarya
import (
"os"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
)
// S3Client initializes a new S3 client that can be used in S3 actions.
// Endpoint will be set to a localstack endpoint when running tests,
// otherwise it will use the default AWS location. Localstack requires
// S3ForcePathStyle is set to true, however, on production it will be set
// to false.
func S3Client(region string) *s3.S3 {
pathStyle := false
if os.Getenv("CI") == "true" {
pathStyle = true
}
return s3.New(
session.Must(session.NewSessionWithOptions(session.Options{
SharedConfigState: session.SharedConfigEnable,
})),
&aws.Config{
Region: aws.String(region),
Endpoint: aws.String(os.Getenv("AWS_S3_ENDPOINT")),
S3ForcePathStyle: aws.Bool(pathStyle),
},
)
}