forked from dugancathal/dynago
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_env.go
44 lines (37 loc) · 1.26 KB
/
client_env.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
34
35
36
37
38
39
40
41
42
43
44
package dynago
import (
"errors"
"os"
)
/*
NewAwsClientFromEnv is a shortcut to create a new dynamo client set up for AWS executor.
It retrieves credentials from the environment variables of the running process.
Environment variables used:
* Access Key ID: AWS_ACCESS_KEY_ID or AWS_ACCESS_KEY
* Secret Access Key: AWS_SECRET_ACCESS_KEY or AWS_SECRET_KEY
* Region: AWS_REGION
* Security Token: AWS_SESSION_TOKEN (optional)
*/
func NewAwsClientFromEnv() (*Client, error) {
accessKey := os.Getenv("AWS_ACCESS_KEY_ID")
if accessKey == "" {
accessKey = os.Getenv("AWS_ACCESS_KEY")
if accessKey == "" {
return nil, errors.New("AWS_ACCESS_KEY_ID or AWS_ACCESS_KEY not found in environment")
}
}
secretKey := os.Getenv("AWS_SECRET_ACCESS_KEY")
if secretKey == "" {
secretKey = os.Getenv("AWS_SECRET_KEY")
if secretKey == "" {
return nil, errors.New("AWS_SECRET_ACCESS_KEY or AWS_SECRET_KEY not found in environment")
}
}
region := os.Getenv("AWS_REGION")
if region == "" {
return nil, errors.New("AWS_REGION not found in environment")
}
sessionToken := os.Getenv("AWS_SESSION_TOKEN")
endpoint := "https://dynamodb." + region + ".amazonaws.com/"
return NewClient(newAwsExecutorToken(endpoint, region, accessKey, secretKey, sessionToken)), nil
}