Skip to content

Commit afa0247

Browse files
committed
Add Environment::endpoint() to return AWS service endpoints
1 parent 6492ac8 commit afa0247

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ class Streaming extends Handler {
155155
return function($event, $context) {
156156

157157
// Send message to WebSocket connection
158-
(new ServiceEndpoint('execute-api', $this->environment->credentials()))
158+
$this->environment->endpoint('execute-api')
159159
->in($context->region)
160160
->using($event['requestContext']['apiId'])
161161
->resource('/{stage}/@connections/{connectionId}', $event['requestContext'])

src/main/php/com/amazon/aws/lambda/Environment.class.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php namespace com\amazon\aws\lambda;
22

3-
use com\amazon\aws\Credentials;
3+
use com\amazon\aws\{Credentials, ServiceEndpoint};
44
use io\Path;
55
use io\streams\StringWriter;
66
use lang\{ElementNotFoundException, Environment as System};
@@ -61,6 +61,16 @@ public function credentials() {
6161
);
6262
}
6363

64+
/**
65+
* Returns an endpoint for a given service
66+
*
67+
* @param string $service
68+
* @return com.amazon.aws.ServiceEndpoint
69+
*/
70+
public function endpoint($service) {
71+
return new ServiceEndpoint($service, $this->credentials());
72+
}
73+
6474
/**
6575
* Writes a trace message
6676
*

src/test/php/com/amazon/aws/lambda/unittest/EnvironmentTest.class.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php namespace com\amazon\aws\lambda\unittest;
22

3-
use com\amazon\aws\Credentials;
43
use com\amazon\aws\lambda\Environment;
4+
use com\amazon\aws\{Credentials, ServiceEndpoint};
55
use io\streams\{MemoryOutputStream, StringWriter};
66
use io\{File, Files, Path};
77
use lang\ElementNotFoundException;
@@ -73,6 +73,18 @@ public function credentials_with_session() {
7373
);
7474
}
7575

76+
#[Test]
77+
public function endpoint() {
78+
Assert::equals(
79+
'id.execute-api.us-east-1.amazonaws.com',
80+
(new Environment('.', null, ['AWS_ACCESS_KEY_ID' => '*', 'AWS_SECRET_ACCESS_KEY' => '*']))
81+
->endpoint('execute-api')
82+
->in('us-east-1')
83+
->using('id')
84+
->domain()
85+
);
86+
}
87+
7688
#[Test]
7789
public function trace() {
7890
$stream= new MemoryOutputStream();

0 commit comments

Comments
 (0)