serverless-http icon indicating copy to clipboard operation
serverless-http copied to clipboard

is there a way for me to get the value of x-amzn-requestid which is passed in from the Lambda context?

Open newbaluku opened this issue 5 years ago • 3 comments

besides x-amzn-requestid, how can I also get the Lambda requestId from my endpoints?

newbaluku avatar Jul 09 '20 10:07 newbaluku

You can use a transformation (https://github.com/dougmoscrop/serverless-http/blob/master/docs/ADVANCED.md#transformations) to basically add anything you want to the request, does that work for you?

dougmoscrop avatar Jul 09 '20 16:07 dougmoscrop

Thanks for the quick response. if I just want to add the context.awsRequestId (Lambda requestId) to all response's header from my endpoints.

Is there an existing way to do it?

I tried this according to the doc: module.exports.handler = serverless(app, { requestId: 'X-ReqId', });

but didn't find any trace of the requestId.

newbaluku avatar Jul 10 '20 14:07 newbaluku

thank you @dougmoscrop for your reference. I was able to solve this with the following:

export interface Context {
  awsRequestId: string;
}

export const handler = serverless(app, {
  request(request: Request, event: any, context: Context) {
    request.requestId = context.awsRequestId || "";
  },
});

denis019 avatar Jun 12 '23 21:06 denis019