Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reading the AWS Request ID #145

Open
harmenjanssen opened this issue Dec 6, 2023 · 9 comments
Open

Reading the AWS Request ID #145

harmenjanssen opened this issue Dec 6, 2023 · 9 comments
Labels
support Someone needs help

Comments

@harmenjanssen
Copy link

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!

@tillkruss
Copy link
Member

Yes:

'request_context' => false,

@tillkruss tillkruss self-assigned this Dec 6, 2023
@harmenjanssen
Copy link
Author

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?

@MantasVaitkunas
Copy link

MantasVaitkunas commented Dec 20, 2023

I am having the same problem. @harmenjanssen can you reopen the issue as ATM it's not clear how to use this config option :/

@tillkruss tillkruss reopened this Dec 20, 2023
@tillkruss tillkruss removed their assignment Dec 20, 2023
@tillkruss tillkruss added the support Someone needs help label Dec 20, 2023
@tillkruss
Copy link
Member

Does your request object not have the X-Request-ID header?

@harmenjanssen
Copy link
Author

Does your request object not have the X-Request-ID header?

Nope, it does not.

@tillkruss
Copy link
Member

Mhhh, turns out my apps aren't actually using this anymore. @georgeboot Do we have any way to access the AWS request id?

@georgeboot
Copy link
Contributor

Afk atm, but there should be a $_SERVER var called HTTP_X_REQUEST_ID I believe

@MantasVaitkunas
Copy link

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;
}

@tillkruss
Copy link
Member

I feel like we should expose the invocation context a little better, maybe even attach some of the data to the Request object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
support Someone needs help
Projects
None yet
Development

No branches or pull requests

4 participants