Skip to content

Commit 586c1fe

Browse files
committed
Set x-aws-lambda-request-id header
1 parent 8d88191 commit 586c1fe

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/lambda.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ declare namespace handler {
88
type APIGatewayEvent = apigw.APIGatewayEvent;
99
type APIGatewayResponse = apigw.LambdaResponse;
1010
type LambdaResponse = apigw.LambdaResponse;
11-
type APIGatewayEventHandler = (event: handler.APIGatewayEvent) => Promise<handler.LambdaResponse>
11+
type LambdaContext = apigw.LambdaContext;
12+
type APIGatewayEventHandler = (event: handler.APIGatewayEvent, context?: handler.LambdaContext) => Promise<handler.LambdaResponse>
1213
};
1314

1415
const eventWithMultiValueHeaders = (event: handler.APIGatewayEvent): boolean => {
@@ -17,15 +18,15 @@ const eventWithMultiValueHeaders = (event: handler.APIGatewayEvent): boolean =>
1718

1819
const handlerPromise = (appPromiseFn: () => Promise<RequestListener>): handler.APIGatewayEventHandler => {
1920
let _p: Promise<RequestListener> | null = null;
20-
return event => {
21+
return (event, ctx) => {
2122
if (!_p) {
2223
_p = appPromiseFn();
2324
}
2425
return _p
2526
.then(app => {
2627
return Promise.resolve()
2728
.then(() => {
28-
const reqOptions = eventToRequestOptions(event);
29+
const reqOptions = eventToRequestOptions(event, ctx);
2930
const appHandler = inProcessRequestHandler(app);
3031
return appHandler(reqOptions)
3132
})

test/integration.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,12 @@ describe('integration', () => {
195195
});
196196
});
197197

198+
it('sets x-aws-lambda-request-id header with context request id', () => {
199+
return handler(event, {awsRequestId: 'req-id'}).then(response => {
200+
expect(response.multiValueHeaders!['x-aws-lambda-request-id']).toEqual('req-id');
201+
});
202+
});
203+
198204
it('works with compressed response', () => {
199205
const myEvent = {
200206
path: "/static/big.html",

0 commit comments

Comments
 (0)