Skip to content

Commit 3201791

Browse files
authored
Refactor endpoint generation (#605)
* Refactor endpoint generation * Regenerate code * Use default case for "global" endpoint * Add an UnsupportedRegion exception * Handle null region * Check region for global * Display only supported versions * Fix cs * Add blank line, and replace PHP_EOL bt \n
1 parent 65b95bb commit 3201791

File tree

1 file changed

+125
-0
lines changed

1 file changed

+125
-0
lines changed

src/LambdaClient.php

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace AsyncAws\Lambda;
44

55
use AsyncAws\Core\AbstractApi;
6+
use AsyncAws\Core\Configuration;
7+
use AsyncAws\Core\Exception\UnsupportedRegion;
68
use AsyncAws\Core\RequestContext;
79
use AsyncAws\Lambda\Input\AddLayerVersionPermissionRequest;
810
use AsyncAws\Lambda\Input\InvocationRequest;
@@ -117,6 +119,129 @@ public function publishLayerVersion($input): PublishLayerVersionResponse
117119
return new PublishLayerVersionResponse($response);
118120
}
119121

122+
protected function getEndpointMetadata(?string $region): array
123+
{
124+
if (null === $region) {
125+
$region = Configuration::DEFAULT_REGION;
126+
}
127+
128+
switch ($region) {
129+
case 'af-south-1':
130+
case 'ap-east-1':
131+
case 'ap-northeast-1':
132+
case 'ap-northeast-2':
133+
case 'ap-south-1':
134+
case 'ap-southeast-1':
135+
case 'ap-southeast-2':
136+
case 'ca-central-1':
137+
case 'eu-central-1':
138+
case 'eu-north-1':
139+
case 'eu-south-1':
140+
case 'eu-west-1':
141+
case 'eu-west-2':
142+
case 'eu-west-3':
143+
case 'me-south-1':
144+
case 'sa-east-1':
145+
case 'us-east-1':
146+
case 'us-east-2':
147+
case 'us-west-1':
148+
case 'us-west-2':
149+
return [
150+
'endpoint' => 'https://lambda.%region%.amazonaws.com',
151+
'signRegion' => $region,
152+
'signService' => 'lambda',
153+
'signVersions' => [
154+
0 => 'v4',
155+
],
156+
];
157+
case 'cn-north-1':
158+
case 'cn-northwest-1':
159+
return [
160+
'endpoint' => 'https://lambda.%region%.amazonaws.com.cn',
161+
'signRegion' => $region,
162+
'signService' => 'lambda',
163+
'signVersions' => [
164+
0 => 'v4',
165+
],
166+
];
167+
case 'us-gov-east-1':
168+
case 'us-gov-west-1':
169+
return [
170+
'endpoint' => 'https://lambda.%region%.amazonaws.com',
171+
'signRegion' => $region,
172+
'signService' => 'lambda',
173+
'signVersions' => [
174+
0 => 'v4',
175+
],
176+
];
177+
case 'us-iso-east-1':
178+
return [
179+
'endpoint' => 'https://lambda.%region%.c2s.ic.gov',
180+
'signRegion' => $region,
181+
'signService' => 'lambda',
182+
'signVersions' => [
183+
0 => 'v4',
184+
],
185+
];
186+
case 'fips-us-east-1':
187+
return [
188+
'endpoint' => 'https://lambda-fips.us-east-1.amazonaws.com',
189+
'signRegion' => 'us-east-1',
190+
'signService' => 'lambda',
191+
'signVersions' => [
192+
0 => 'v4',
193+
],
194+
];
195+
case 'fips-us-east-2':
196+
return [
197+
'endpoint' => 'https://lambda-fips.us-east-2.amazonaws.com',
198+
'signRegion' => 'us-east-2',
199+
'signService' => 'lambda',
200+
'signVersions' => [
201+
0 => 'v4',
202+
],
203+
];
204+
case 'fips-us-gov-east-1':
205+
return [
206+
'endpoint' => 'https://lambda-fips.us-gov-east-1.amazonaws.com',
207+
'signRegion' => 'us-gov-east-1',
208+
'signService' => 'lambda',
209+
'signVersions' => [
210+
0 => 'v4',
211+
],
212+
];
213+
case 'fips-us-gov-west-1':
214+
return [
215+
'endpoint' => 'https://lambda-fips.us-gov-west-1.amazonaws.com',
216+
'signRegion' => 'us-gov-west-1',
217+
'signService' => 'lambda',
218+
'signVersions' => [
219+
0 => 'v4',
220+
],
221+
];
222+
case 'fips-us-west-1':
223+
return [
224+
'endpoint' => 'https://lambda-fips.us-west-1.amazonaws.com',
225+
'signRegion' => 'us-west-1',
226+
'signService' => 'lambda',
227+
'signVersions' => [
228+
0 => 'v4',
229+
],
230+
];
231+
case 'fips-us-west-2':
232+
return [
233+
'endpoint' => 'https://lambda-fips.us-west-2.amazonaws.com',
234+
'signRegion' => 'us-west-2',
235+
'signService' => 'lambda',
236+
'signVersions' => [
237+
0 => 'v4',
238+
],
239+
];
240+
}
241+
242+
throw new UnsupportedRegion(sprintf('The region "%s" is not supported by "Lambda".', $region));
243+
}
244+
120245
protected function getServiceCode(): string
121246
{
122247
return 'lambda';

0 commit comments

Comments
 (0)