File tree Expand file tree Collapse file tree 2 files changed +27
-11
lines changed Expand file tree Collapse file tree 2 files changed +27
-11
lines changed Original file line number Diff line number Diff line change @@ -83,9 +83,11 @@ Add dynamodb configs to config/database.php:
83
83
84
84
'dynamodb' => [
85
85
'driver' => 'dynamodb',
86
- 'region' => env('AWS_DEFAULT_REGION'),
87
- 'access_key' => env('AWS_ACCESS_KEY_ID'),
88
- 'secret_key' => env('AWS_SECRET_ACCESS_KEY')
86
+ 'key' => env('AWS_ACCESS_KEY_ID'),
87
+ 'secret' => env('AWS_SECRET_ACCESS_KEY'),
88
+ 'token' => env('AWS_SESSION_TOKEN'),
89
+ 'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
90
+ 'endpoint' => env('DYNAMODB_ENDPOINT'),
89
91
],
90
92
91
93
...
Original file line number Diff line number Diff line change 5
5
use Aws \Sdk as AwsSdk ;
6
6
use Aws \DynamoDb \DynamoDbClient ;
7
7
use Illuminate \Database \Connection as BaseConnection ;
8
+ use Illuminate \Support \Arr ;
8
9
9
10
class Connection extends BaseConnection
10
11
{
@@ -70,16 +71,29 @@ public function setClient(DynamoDbClient $client)
70
71
*/
71
72
protected function createClient (array $ config )
72
73
{
73
- $ sdk = new AwsSdk ( [
74
+ $ dynamoConfig = [
74
75
'region ' => $ config ['region ' ] ?? 'us-east-1 ' ,
75
76
'version ' => $ config ['version ' ] ?? 'latest ' ,
76
- 'credentials ' => [
77
- 'key ' => $ config ['access_key ' ] ?? '' ,
78
- 'secret ' => $ config ['secret_key ' ] ?? ''
79
- ]
80
- ]);
81
-
82
- return $ sdk ->createDynamoDb ();
77
+ 'endpoint ' => $ config ['endpoint ' ] ?? null ,
78
+ ];
79
+
80
+ if ($ key = $ config ['access_key ' ] ?? null ) {
81
+ $ config ['key ' ] = $ key ;
82
+ unset($ config ['access_key ' ]);
83
+ }
84
+
85
+ if ($ key = $ config ['secret_key ' ] ?? null ) {
86
+ $ config ['secret ' ] = $ key ;
87
+ unset($ config ['secret_key ' ]);
88
+ }
89
+
90
+ if (isset ($ config ['key ' ]) && isset ($ config ['secret ' ])) {
91
+ $ dynamoConfig ['credentials ' ] = Arr::only (
92
+ $ config , ['key ' , 'secret ' , 'token ' ]
93
+ );
94
+ }
95
+
96
+ return (new AwsSdk ($ dynamoConfig ))->createDynamoDb ();
83
97
}
84
98
85
99
/**
You can’t perform that action at this time.
0 commit comments