Skip to content

Commit 481cf91

Browse files
committed
Fix not being able to invoke streaming handler more than once
1 parent 1645f0c commit 481cf91

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,10 @@ public function end() {
114114
}
115115

116116
public function invoke($lambda, $event, $context) {
117+
$this->request= $this->api->request('POST', "invocation/{$context->awsRequestId}/response");
118+
$this->response= $this->stream= null;
119+
117120
try {
118-
$this->request= $this->api->request('POST', "invocation/{$context->awsRequestId}/response");
119121
$lambda($event, $this, $context);
120122
$this->end();
121123
return $this->response;

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,18 @@ public function transmit() {
126126
);
127127
}
128128

129+
#[Test]
130+
public function invoke_handler_multiple_times() {
131+
$lambda= function($event, $stream, $context) { $stream->write('Test'); };
132+
$streaming= $this->runtime->streaming();
133+
134+
foreach (['3e1afeb0-cde4-1d0e-c3c0-66b15046bb88', '46c40f55-2a88-4b69-857c-26460e56b2e1'] as $id) {
135+
$request= ['Lambda-Runtime-Aws-Request-Id' => [$id]];
136+
$response= $streaming->invoke($lambda, null, new Context($request + $this->headers, $this->environment));
137+
Assert::matches("/^POST .+\/{$id}\/response/", $response->readData());
138+
}
139+
}
140+
129141
#[Test, Expect(IllegalStateException::class)]
130142
public function writing_after_end() {
131143
$this->invoke(function($event, $stream, $context) {

0 commit comments

Comments
 (0)