Skip to content

Commit 320600f

Browse files
authored
Add supports for multi-region (#466)
* Allow custom region at run time * Regenerate code * Add changelog entry * Add docbloc on Input without members
1 parent c9304aa commit 320600f

12 files changed

+67
-24
lines changed

src/DynamoDbClient.php

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,13 @@ class DynamoDbClient extends AbstractApi
4848
* StreamSpecification?: \AsyncAws\DynamoDb\ValueObject\StreamSpecification|array,
4949
* SSESpecification?: \AsyncAws\DynamoDb\ValueObject\SSESpecification|array,
5050
* Tags?: \AsyncAws\DynamoDb\ValueObject\Tag[],
51+
* @region?: string,
5152
* }|CreateTableInput $input
5253
*/
5354
public function createTable($input): CreateTableOutput
5455
{
55-
$response = $this->getResponse(CreateTableInput::create($input)->request(), new RequestContext(['operation' => 'CreateTable']));
56+
$input = CreateTableInput::create($input);
57+
$response = $this->getResponse($input->request(), new RequestContext(['operation' => 'CreateTable', 'region' => $input->getRegion()]));
5658

5759
return new CreateTableOutput($response);
5860
}
@@ -74,11 +76,13 @@ public function createTable($input): CreateTableOutput
7476
* ConditionExpression?: string,
7577
* ExpressionAttributeNames?: string[],
7678
* ExpressionAttributeValues?: \AsyncAws\DynamoDb\ValueObject\AttributeValue[],
79+
* @region?: string,
7780
* }|DeleteItemInput $input
7881
*/
7982
public function deleteItem($input): DeleteItemOutput
8083
{
81-
$response = $this->getResponse(DeleteItemInput::create($input)->request(), new RequestContext(['operation' => 'DeleteItem']));
84+
$input = DeleteItemInput::create($input);
85+
$response = $this->getResponse($input->request(), new RequestContext(['operation' => 'DeleteItem', 'region' => $input->getRegion()]));
8286

8387
return new DeleteItemOutput($response);
8488
}
@@ -94,11 +98,13 @@ public function deleteItem($input): DeleteItemOutput
9498
*
9599
* @param array{
96100
* TableName: string,
101+
* @region?: string,
97102
* }|DeleteTableInput $input
98103
*/
99104
public function deleteTable($input): DeleteTableOutput
100105
{
101-
$response = $this->getResponse(DeleteTableInput::create($input)->request(), new RequestContext(['operation' => 'DeleteTable']));
106+
$input = DeleteTableInput::create($input);
107+
$response = $this->getResponse($input->request(), new RequestContext(['operation' => 'DeleteTable', 'region' => $input->getRegion()]));
102108

103109
return new DeleteTableOutput($response);
104110
}
@@ -111,11 +117,13 @@ public function deleteTable($input): DeleteTableOutput
111117
*
112118
* @param array{
113119
* TableName: string,
120+
* @region?: string,
114121
* }|DescribeTableInput $input
115122
*/
116123
public function describeTable($input): DescribeTableOutput
117124
{
118-
$response = $this->getResponse(DescribeTableInput::create($input)->request(), new RequestContext(['operation' => 'DescribeTable']));
125+
$input = DescribeTableInput::create($input);
126+
$response = $this->getResponse($input->request(), new RequestContext(['operation' => 'DescribeTable', 'region' => $input->getRegion()]));
119127

120128
return new DescribeTableOutput($response);
121129
}
@@ -134,11 +142,13 @@ public function describeTable($input): DescribeTableOutput
134142
* ReturnConsumedCapacity?: \AsyncAws\DynamoDb\Enum\ReturnConsumedCapacity::*,
135143
* ProjectionExpression?: string,
136144
* ExpressionAttributeNames?: string[],
145+
* @region?: string,
137146
* }|GetItemInput $input
138147
*/
139148
public function getItem($input): GetItemOutput
140149
{
141-
$response = $this->getResponse(GetItemInput::create($input)->request(), new RequestContext(['operation' => 'GetItem']));
150+
$input = GetItemInput::create($input);
151+
$response = $this->getResponse($input->request(), new RequestContext(['operation' => 'GetItem', 'region' => $input->getRegion()]));
142152

143153
return new GetItemOutput($response);
144154
}
@@ -152,12 +162,13 @@ public function getItem($input): GetItemOutput
152162
* @param array{
153163
* ExclusiveStartTableName?: string,
154164
* Limit?: int,
165+
* @region?: string,
155166
* }|ListTablesInput $input
156167
*/
157168
public function listTables($input = []): ListTablesOutput
158169
{
159170
$input = ListTablesInput::create($input);
160-
$response = $this->getResponse($input->request(), new RequestContext(['operation' => 'ListTables']));
171+
$response = $this->getResponse($input->request(), new RequestContext(['operation' => 'ListTables', 'region' => $input->getRegion()]));
161172

162173
return new ListTablesOutput($response, $this, $input);
163174
}
@@ -182,11 +193,13 @@ public function listTables($input = []): ListTablesOutput
182193
* ConditionExpression?: string,
183194
* ExpressionAttributeNames?: string[],
184195
* ExpressionAttributeValues?: \AsyncAws\DynamoDb\ValueObject\AttributeValue[],
196+
* @region?: string,
185197
* }|PutItemInput $input
186198
*/
187199
public function putItem($input): PutItemOutput
188200
{
189-
$response = $this->getResponse(PutItemInput::create($input)->request(), new RequestContext(['operation' => 'PutItem']));
201+
$input = PutItemInput::create($input);
202+
$response = $this->getResponse($input->request(), new RequestContext(['operation' => 'PutItem', 'region' => $input->getRegion()]));
190203

191204
return new PutItemOutput($response);
192205
}
@@ -215,12 +228,13 @@ public function putItem($input): PutItemOutput
215228
* KeyConditionExpression?: string,
216229
* ExpressionAttributeNames?: string[],
217230
* ExpressionAttributeValues?: \AsyncAws\DynamoDb\ValueObject\AttributeValue[],
231+
* @region?: string,
218232
* }|QueryInput $input
219233
*/
220234
public function query($input): QueryOutput
221235
{
222236
$input = QueryInput::create($input);
223-
$response = $this->getResponse($input->request(), new RequestContext(['operation' => 'Query']));
237+
$response = $this->getResponse($input->request(), new RequestContext(['operation' => 'Query', 'region' => $input->getRegion()]));
224238

225239
return new QueryOutput($response, $this, $input);
226240
}
@@ -248,12 +262,13 @@ public function query($input): QueryOutput
248262
* ExpressionAttributeNames?: string[],
249263
* ExpressionAttributeValues?: \AsyncAws\DynamoDb\ValueObject\AttributeValue[],
250264
* ConsistentRead?: bool,
265+
* @region?: string,
251266
* }|ScanInput $input
252267
*/
253268
public function scan($input): ScanOutput
254269
{
255270
$input = ScanInput::create($input);
256-
$response = $this->getResponse($input->request(), new RequestContext(['operation' => 'Scan']));
271+
$response = $this->getResponse($input->request(), new RequestContext(['operation' => 'Scan', 'region' => $input->getRegion()]));
257272

258273
return new ScanOutput($response, $this, $input);
259274
}
@@ -265,12 +280,13 @@ public function scan($input): ScanOutput
265280
*
266281
* @param array{
267282
* TableName: string,
283+
* @region?: string,
268284
* }|DescribeTableInput $input
269285
*/
270286
public function tableExists($input): TableExistsWaiter
271287
{
272288
$input = DescribeTableInput::create($input);
273-
$response = $this->getResponse($input->request(), new RequestContext(['operation' => 'DescribeTable']));
289+
$response = $this->getResponse($input->request(), new RequestContext(['operation' => 'DescribeTable', 'region' => $input->getRegion()]));
274290

275291
return new TableExistsWaiter($response, $this, $input);
276292
}
@@ -282,12 +298,13 @@ public function tableExists($input): TableExistsWaiter
282298
*
283299
* @param array{
284300
* TableName: string,
301+
* @region?: string,
285302
* }|DescribeTableInput $input
286303
*/
287304
public function tableNotExists($input): TableNotExistsWaiter
288305
{
289306
$input = DescribeTableInput::create($input);
290-
$response = $this->getResponse($input->request(), new RequestContext(['operation' => 'DescribeTable']));
307+
$response = $this->getResponse($input->request(), new RequestContext(['operation' => 'DescribeTable', 'region' => $input->getRegion()]));
291308

292309
return new TableNotExistsWaiter($response, $this, $input);
293310
}
@@ -313,11 +330,13 @@ public function tableNotExists($input): TableNotExistsWaiter
313330
* ConditionExpression?: string,
314331
* ExpressionAttributeNames?: string[],
315332
* ExpressionAttributeValues?: \AsyncAws\DynamoDb\ValueObject\AttributeValue[],
333+
* @region?: string,
316334
* }|UpdateItemInput $input
317335
*/
318336
public function updateItem($input): UpdateItemOutput
319337
{
320-
$response = $this->getResponse(UpdateItemInput::create($input)->request(), new RequestContext(['operation' => 'UpdateItem']));
338+
$input = UpdateItemInput::create($input);
339+
$response = $this->getResponse($input->request(), new RequestContext(['operation' => 'UpdateItem', 'region' => $input->getRegion()]));
321340

322341
return new UpdateItemOutput($response);
323342
}
@@ -337,11 +356,13 @@ public function updateItem($input): UpdateItemOutput
337356
* StreamSpecification?: \AsyncAws\DynamoDb\ValueObject\StreamSpecification|array,
338357
* SSESpecification?: \AsyncAws\DynamoDb\ValueObject\SSESpecification|array,
339358
* ReplicaUpdates?: \AsyncAws\DynamoDb\ValueObject\ReplicationGroupUpdate[],
359+
* @region?: string,
340360
* }|UpdateTableInput $input
341361
*/
342362
public function updateTable($input): UpdateTableOutput
343363
{
344-
$response = $this->getResponse(UpdateTableInput::create($input)->request(), new RequestContext(['operation' => 'UpdateTable']));
364+
$input = UpdateTableInput::create($input);
365+
$response = $this->getResponse($input->request(), new RequestContext(['operation' => 'UpdateTable', 'region' => $input->getRegion()]));
345366

346367
return new UpdateTableOutput($response);
347368
}

src/Input/CreateTableInput.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use AsyncAws\DynamoDb\ValueObject\StreamSpecification;
1717
use AsyncAws\DynamoDb\ValueObject\Tag;
1818

19-
final class CreateTableInput implements Input
19+
final class CreateTableInput extends Input
2020
{
2121
/**
2222
* An array of attributes that describe the key schema for the table and indexes.
@@ -116,6 +116,7 @@ final class CreateTableInput implements Input
116116
* StreamSpecification?: \AsyncAws\DynamoDb\ValueObject\StreamSpecification|array,
117117
* SSESpecification?: \AsyncAws\DynamoDb\ValueObject\SSESpecification|array,
118118
* Tags?: \AsyncAws\DynamoDb\ValueObject\Tag[],
119+
* @region?: string,
119120
* } $input
120121
*/
121122
public function __construct(array $input = [])
@@ -130,6 +131,7 @@ public function __construct(array $input = [])
130131
$this->StreamSpecification = isset($input['StreamSpecification']) ? StreamSpecification::create($input['StreamSpecification']) : null;
131132
$this->SSESpecification = isset($input['SSESpecification']) ? SSESpecification::create($input['SSESpecification']) : null;
132133
$this->Tags = array_map([Tag::class, 'create'], $input['Tags'] ?? []);
134+
parent::__construct($input);
133135
}
134136

135137
public static function create($input): self

src/Input/DeleteItemInput.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use AsyncAws\DynamoDb\ValueObject\AttributeValue;
1414
use AsyncAws\DynamoDb\ValueObject\ExpectedAttributeValue;
1515

16-
final class DeleteItemInput implements Input
16+
final class DeleteItemInput extends Input
1717
{
1818
/**
1919
* The name of the table from which to delete the item.
@@ -109,6 +109,7 @@ final class DeleteItemInput implements Input
109109
* ConditionExpression?: string,
110110
* ExpressionAttributeNames?: string[],
111111
* ExpressionAttributeValues?: \AsyncAws\DynamoDb\ValueObject\AttributeValue[],
112+
* @region?: string,
112113
* } $input
113114
*/
114115
public function __construct(array $input = [])
@@ -135,6 +136,7 @@ public function __construct(array $input = [])
135136
foreach ($input['ExpressionAttributeValues'] ?? [] as $key => $item) {
136137
$this->ExpressionAttributeValues[$key] = AttributeValue::create($item);
137138
}
139+
parent::__construct($input);
138140
}
139141

140142
public static function create($input): self

src/Input/DeleteTableInput.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use AsyncAws\Core\Request;
88
use AsyncAws\Core\Stream\StreamFactory;
99

10-
final class DeleteTableInput implements Input
10+
final class DeleteTableInput extends Input
1111
{
1212
/**
1313
* The name of the table to delete.
@@ -21,11 +21,13 @@ final class DeleteTableInput implements Input
2121
/**
2222
* @param array{
2323
* TableName?: string,
24+
* @region?: string,
2425
* } $input
2526
*/
2627
public function __construct(array $input = [])
2728
{
2829
$this->TableName = $input['TableName'] ?? null;
30+
parent::__construct($input);
2931
}
3032

3133
public static function create($input): self

src/Input/DescribeTableInput.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use AsyncAws\Core\Request;
88
use AsyncAws\Core\Stream\StreamFactory;
99

10-
final class DescribeTableInput implements Input
10+
final class DescribeTableInput extends Input
1111
{
1212
/**
1313
* The name of the table to describe.
@@ -21,11 +21,13 @@ final class DescribeTableInput implements Input
2121
/**
2222
* @param array{
2323
* TableName?: string,
24+
* @region?: string,
2425
* } $input
2526
*/
2627
public function __construct(array $input = [])
2728
{
2829
$this->TableName = $input['TableName'] ?? null;
30+
parent::__construct($input);
2931
}
3032

3133
public static function create($input): self

src/Input/GetItemInput.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use AsyncAws\DynamoDb\Enum\ReturnConsumedCapacity;
1010
use AsyncAws\DynamoDb\ValueObject\AttributeValue;
1111

12-
final class GetItemInput implements Input
12+
final class GetItemInput extends Input
1313
{
1414
/**
1515
* The name of the table containing the requested item.
@@ -77,6 +77,7 @@ final class GetItemInput implements Input
7777
* ReturnConsumedCapacity?: \AsyncAws\DynamoDb\Enum\ReturnConsumedCapacity::*,
7878
* ProjectionExpression?: string,
7979
* ExpressionAttributeNames?: string[],
80+
* @region?: string,
8081
* } $input
8182
*/
8283
public function __construct(array $input = [])
@@ -92,6 +93,7 @@ public function __construct(array $input = [])
9293
$this->ReturnConsumedCapacity = $input['ReturnConsumedCapacity'] ?? null;
9394
$this->ProjectionExpression = $input['ProjectionExpression'] ?? null;
9495
$this->ExpressionAttributeNames = $input['ExpressionAttributeNames'] ?? [];
96+
parent::__construct($input);
9597
}
9698

9799
public static function create($input): self

src/Input/ListTablesInput.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use AsyncAws\Core\Request;
77
use AsyncAws\Core\Stream\StreamFactory;
88

9-
final class ListTablesInput implements Input
9+
final class ListTablesInput extends Input
1010
{
1111
/**
1212
* The first table name that this operation will evaluate. Use the value that was returned for `LastEvaluatedTableName`
@@ -27,12 +27,14 @@ final class ListTablesInput implements Input
2727
* @param array{
2828
* ExclusiveStartTableName?: string,
2929
* Limit?: int,
30+
* @region?: string,
3031
* } $input
3132
*/
3233
public function __construct(array $input = [])
3334
{
3435
$this->ExclusiveStartTableName = $input['ExclusiveStartTableName'] ?? null;
3536
$this->Limit = $input['Limit'] ?? null;
37+
parent::__construct($input);
3638
}
3739

3840
public static function create($input): self

src/Input/PutItemInput.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use AsyncAws\DynamoDb\ValueObject\AttributeValue;
1414
use AsyncAws\DynamoDb\ValueObject\ExpectedAttributeValue;
1515

16-
final class PutItemInput implements Input
16+
final class PutItemInput extends Input
1717
{
1818
/**
1919
* The name of the table to contain the item.
@@ -110,6 +110,7 @@ final class PutItemInput implements Input
110110
* ConditionExpression?: string,
111111
* ExpressionAttributeNames?: string[],
112112
* ExpressionAttributeValues?: \AsyncAws\DynamoDb\ValueObject\AttributeValue[],
113+
* @region?: string,
113114
* } $input
114115
*/
115116
public function __construct(array $input = [])
@@ -136,6 +137,7 @@ public function __construct(array $input = [])
136137
foreach ($input['ExpressionAttributeValues'] ?? [] as $key => $item) {
137138
$this->ExpressionAttributeValues[$key] = AttributeValue::create($item);
138139
}
140+
parent::__construct($input);
139141
}
140142

141143
public static function create($input): self

src/Input/QueryInput.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use AsyncAws\DynamoDb\ValueObject\AttributeValue;
1313
use AsyncAws\DynamoDb\ValueObject\Condition;
1414

15-
final class QueryInput implements Input
15+
final class QueryInput extends Input
1616
{
1717
/**
1818
* The name of the table containing the requested items.
@@ -180,6 +180,7 @@ final class QueryInput implements Input
180180
* KeyConditionExpression?: string,
181181
* ExpressionAttributeNames?: string[],
182182
* ExpressionAttributeValues?: \AsyncAws\DynamoDb\ValueObject\AttributeValue[],
183+
* @region?: string,
183184
* } $input
184185
*/
185186
public function __construct(array $input = [])
@@ -217,6 +218,7 @@ public function __construct(array $input = [])
217218
foreach ($input['ExpressionAttributeValues'] ?? [] as $key => $item) {
218219
$this->ExpressionAttributeValues[$key] = AttributeValue::create($item);
219220
}
221+
parent::__construct($input);
220222
}
221223

222224
public static function create($input): self

0 commit comments

Comments
 (0)