-
-
Notifications
You must be signed in to change notification settings - Fork 367
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
Pass the Lambda context to handlers #311
Conversation
That's really interesting! I think we can do without the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for working on this, this is really a great change and it brings us closer to other languages!
moved Context object to its own namespace made Context immutable by removing its setters and adding a constructor added a ContextBuilder that will build an immutable Context object adjusted curl's header function to use context builder adjusted tests improved phpdoc blocks
if ($body === '') { | ||
throw new \Exception('Empty Lambda runtime API response'); | ||
} | ||
|
||
$context = $contextBuilder->buildContext(); | ||
|
||
if ($context->getAwsRequestId() === '') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is a Context with an empty aws request id valid? Maybe this check should be moved in the ContextBuilder? (same question for the other properties of the context, what is the minimal set of data that constitutes a valid context?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
context can be completely empty but that piece of code expects a non-empty invocation id. It's just a coincidence I'm refetching it from the context instead of keeping around in an $invocationId variable. I could do revert back to using a $invocationId variable in that piece of code and build the context last just before return
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might ideally be better indeed to forbid having an invalid Context around, but honestly this should never happen and an exception will be thrown if it ever happens. Let's not block this PR longer than necessary.
Thank you for updating your PR @amne.
We would like access to the aws-request-id header that is returned by the runtime API.
Our specific use case is that we use the request id to correlate log entries generated by this lambda invocation. Initially we generated our own correlation id but we noticed we can't link them to the cloudwatch entries but we can link them if we use the lambda request id as the correlation id.