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:
8383
8484 'dynamodb' => [
8585 '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'),
8991 ],
9092
9193 ...
Original file line number Diff line number Diff line change 55use Aws \Sdk as AwsSdk ;
66use Aws \DynamoDb \DynamoDbClient ;
77use Illuminate \Database \Connection as BaseConnection ;
8+ use Illuminate \Support \Arr ;
89
910class Connection extends BaseConnection
1011{
@@ -70,16 +71,29 @@ public function setClient(DynamoDbClient $client)
7071 */
7172 protected function createClient (array $ config )
7273 {
73- $ sdk = new AwsSdk ( [
74+ $ dynamoConfig = [
7475 'region ' => $ config ['region ' ] ?? 'us-east-1 ' ,
7576 '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 ();
8397 }
8498
8599 /**
You can’t perform that action at this time.
0 commit comments