Skip to content

Commit d97ec03

Browse files
committed
Pass LAMBDA_REQUEST_ID to PHP-FPM
The function and console runtimes set it on every invocation, PHP-FPM workers only received LAMBDA_INVOCATION_CONTEXT. Claude-Session: https://claude.ai/code/session_0168N55uBK9UjfpL6r8oGjDm
1 parent da2e791 commit d97ec03

3 files changed

Lines changed: 5 additions & 0 deletions

File tree

‎docs/runtimes/fpm-runtime.mdx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ Here is an example to retrieve it:
7070
$lambdaContext = json_decode($_SERVER['LAMBDA_INVOCATION_CONTEXT'], true);
7171
```
7272

73+
The request ID of the invocation is also available directly in `$_SERVER['LAMBDA_REQUEST_ID']`, like in [the other runtimes](./runtimes-details.mdx#environment-variables).
74+
7375
### Request context
7476

7577
API Gateway integrations can add information to the HTTP request via the *request context*.

‎src/FpmRuntime/FpmHandler.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,8 @@ private function eventToFastCgiRequest(HttpRequestEvent $event, Context $context
253253
$request->setCustomVar('PATH_INFO', $event->getPath());
254254
$request->setCustomVar('QUERY_STRING', $event->getQueryString());
255255
$request->setCustomVar('LAMBDA_INVOCATION_CONTEXT', json_encode($context, JSON_THROW_ON_ERROR));
256+
// Same variable as in the other runtimes, see LambdaRuntime::processNextEvent()
257+
$request->setCustomVar('LAMBDA_REQUEST_ID', $context->getAwsRequestId());
256258
$request->setCustomVar('LAMBDA_REQUEST_CONTEXT', json_encode($event->getRequestContext(), JSON_THROW_ON_ERROR));
257259

258260
$contentType = $event->getContentType();

‎tests/FpmRuntime/FpmHandlerTest.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,6 +1325,7 @@ private function assertCommonServerVariables(array $response, array $expectedGlo
13251325
'SCRIPT_FILENAME' => __DIR__ . '/fixtures/request.php',
13261326
'GATEWAY_INTERFACE' => 'FastCGI/1.0',
13271327
'FCGI_ROLE' => 'RESPONDER',
1328+
'LAMBDA_REQUEST_ID' => 'abc',
13281329
];
13291330

13301331
// Allow to override some keys

0 commit comments

Comments
 (0)