laravel-bridge
laravel-bridge copied to clipboard
Reading the AWS Request ID
Hi,
I was wondering if it's possible to get at the original Lambda Request ID within your Laravel app?
I found the Context class which has a reference to the ID, but I'm unsure if that's accessible from within my Laravel app. (tried dependency-injecting it, but that was not the answer)
Thanks a lot in advance!
Yes: https://github.com/brefphp/laravel-bridge/blob/2bff7e67ed11f833329cfd5340f7d3e606347e54/config/bref.php#L31
Hmm, alright, I have to be more specific I guess: at this point I am not getting the X-Request-ID
header in my requests.
I turned request_context
on, but that doesn't give me any information about the AWS request.
I'm logging all headers coming in to my controller via the request, but it's not there. Is there a way to get at the current context either in a controller, or middleware, or somewhere in that chain?
I am having the same problem. @harmenjanssen can you reopen the issue as ATM it's not clear how to use this config option :/
Does your request object not have the X-Request-ID
header?
Does your request object not have the
X-Request-ID
header?
Nope, it does not.
Mhhh, turns out my apps aren't actually using this anymore. @georgeboot Do we have any way to access the AWS request id?
Afk atm, but there should be a $_SERVER var called HTTP_X_REQUEST_ID I believe
As @georgeboot said, I had a look into $_SERVER and found out that $_SERVER['LAMBDA_INVOCATION_CONTEXT'] has necessary info:
$requestId = null;
if (isset($_SERVER['LAMBDA_INVOCATION_CONTEXT'])) {
$lambdaContext = json_decode($_SERVER['LAMBDA_INVOCATION_CONTEXT']);
$requestId = $lambdaContext?->awsRequestId;
}
I feel like we should expose the invocation context a little better, maybe even attach some of the data to the Request
object.