dougmoscrop / serverless-http

Use your existing middleware framework (e.g. Express, Koa) in AWS Lambda 🎉
Other
1.72k stars 165 forks source link

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

Open newbaluku opened 4 years ago

newbaluku commented 4 years ago

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

dougmoscrop commented 4 years ago

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?

newbaluku commented 4 years ago

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.

denis019 commented 1 year ago

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 || "";
  },
});