Skip to content

Commit 051ebcc

Browse files
committed
filling out request context so middy understands it
1 parent cb803b3 commit 051ebcc

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

src/index.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env node --loader ts-node/esm --no-warnings
22

3+
import { APIGatewayEventIdentity } from 'aws-lambda/common/api-gateway';
34
import {Command} from "commander";
45
import * as tsNode from "ts-node";
56
import cors from "cors";
@@ -146,7 +147,7 @@ function functionFor(
146147

147148
return async (req, res) => {
148149
const headers = req.headers;
149-
const requestContext = useCognitoClaims ? {requestContext: extractCognitoRequestContext(req)} : {};
150+
const authorizer = useCognitoClaims ? extractCognitoRequestContext(req) : undefined;
150151
const pathParameters = Object.keys(req.params).reduce(
151152
(acc, key) => ({
152153
...acc,
@@ -157,16 +158,30 @@ function functionFor(
157158
const queryParams = queryParameters(
158159
(req.query ?? {}) as { [key: string]: undefined | string | string[] }
159160
);
160-
const event: APIGatewayProxyEvent = {
161-
headers: headers as APIGatewayProxyEvent["headers"],
161+
const event = {
162+
headers: headers,
162163
resource: path,
163164
body: (req as any).rawBody,
164165
httpMethod: method.toUpperCase(),
165166
pathParameters,
166167
path: req.path,
167-
...requestContext,
168-
...queryParams,
169-
} as unknown as APIGatewayProxyEvent;
168+
isBase64Encoded: false,
169+
requestContext: {
170+
path: req.path,
171+
authorizer,
172+
httpMethod: method.toUpperCase(),
173+
resourcePath: path,
174+
requestTimeEpoch: 0,
175+
requestTime: '',
176+
requestId: '0',
177+
identity: {} as unknown as APIGatewayEventIdentity,
178+
protocol: 'http',
179+
stage: 'dev',
180+
apiId: '',
181+
accountId: ''
182+
},
183+
...queryParams
184+
} as unknown as APIGatewayProxyEvent
170185
const code = await import(`${codeLocation}?update=${Date.now()}`);
171186
code[handler](event)
172187
.then((response: any) => {

0 commit comments

Comments
 (0)