File tree Expand file tree Collapse file tree 2 files changed +22
-12
lines changed Expand file tree Collapse file tree 2 files changed +22
-12
lines changed Original file line number Diff line number Diff line change @@ -12,14 +12,28 @@ var DynamoDB *dynamodb.DynamoDB
12
12
13
13
// GetDynamoSession returns a new dynamodb session
14
14
func GetDynamoSession (accessKeyID , secretAccessKey , region string ) * dynamodb.DynamoDB {
15
- token := ""
16
- creds := credentials .NewStaticCredentials (accessKeyID , secretAccessKey , token )
17
- _ , err := creds .Get ()
18
- if err != nil {
19
- panic (err )
15
+ session_config := session.Options {}
16
+ if accessKeyID != "" || secretAccessKey != "" {
17
+ token := ""
18
+ creds := credentials .NewStaticCredentials (accessKeyID , secretAccessKey , token )
19
+ _ , err := creds .Get ()
20
+ if err != nil {
21
+ panic (err )
22
+ }
23
+ session_config .Config .Credentials = creds
20
24
}
21
25
22
- DynamoDB = dynamodb .New (session .New (& aws.Config {Region : & region }))
26
+ if region != "" {
27
+ session_config .Config .Region = & region
28
+ } else {
29
+ session_config .SharedConfigState = session .SharedConfigEnable
30
+ }
31
+
32
+ session , err := session .NewSessionWithOptions (session_config )
33
+ if err != nil {
34
+ panic (err )
35
+ }
36
+ DynamoDB = dynamodb .New (session )
23
37
return DynamoDB
24
38
}
25
39
Original file line number Diff line number Diff line change @@ -213,12 +213,8 @@ func main() {
213
213
},
214
214
},
215
215
Action : func (c * cli.Context ) error {
216
- if region == "" {
217
- fmt .Println ("Must provide aws config region" )
218
- } else if accessKeyID == "" {
219
- fmt .Println ("Must provide aws config access key id" )
220
- } else if secretAccessKey == "" {
221
- fmt .Println ("Must provide aws config secret access key" )
216
+ if ! ((accessKeyID == "" && secretAccessKey == "" ) || (accessKeyID != "" && secretAccessKey != "" )){
217
+ fmt .Println ("Must provide access key id and secret access key at the same time" )
222
218
} else {
223
219
db .GetDynamoSession (accessKeyID , secretAccessKey , region )
224
220
runPrompt (tablePrefix )
You can’t perform that action at this time.
0 commit comments