-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaws.go
31 lines (27 loc) · 827 Bytes
/
aws.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
package main
import (
"log"
"sync"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
)
var (
awsSession *session.Session
once sync.Once
)
// initAWSSession initializes a new AWS session on its first call and returns the same session on subsequent calls.
func initAWSSession(awsRegion string, awsEndpoint string, awsAccessKeyId string, awsSecretAccessKey string) *session.Session {
once.Do(func() {
var err error
awsSession, err = session.NewSession(&aws.Config{
Region: aws.String(awsRegion),
Endpoint: aws.String(awsEndpoint),
Credentials: credentials.NewStaticCredentials(awsAccessKeyId, awsSecretAccessKey, ""),
})
if err != nil {
log.Fatalf("Failed to create AWS session: %s", err)
}
})
return awsSession
}