Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
tomrf1 committed Dec 17, 2024
1 parent be9057f commit 02488b7
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions src/lib/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,30 @@ import {
SQSHandler,
} from 'aws-lambda';

const getHandler =
<INPUT, OUTPUT>(run: (event: INPUT) => Promise<OUTPUT>) =>
(event: INPUT, context: Context, callback: Callback<OUTPUT>): void => {
// setTimeout is necessary because of a bug in the node lambda runtime which can break requests to ssm
setTimeout(() => {
// If we do not set this then the lambda will wait 10secs before completing.
// This is because pg starts a 10sec timer for each new client (see idleTimeoutMillis in https://node-postgres.com/api/pool).
// `callbackWaitsForEmptyEventLoop = false` ensures the invocation ends immediately (https://docs.aws.amazon.com/lambda/latest/dg/nodejs-context.html)
context.callbackWaitsForEmptyEventLoop = false;
const getHandler = <INPUT, OUTPUT>(run: (event: INPUT) => Promise<OUTPUT>) => (
event: INPUT,
context: Context,
callback: Callback<OUTPUT>,
): void => {
// setTimeout is necessary because of a bug in the node lambda runtime which can break requests to ssm
setTimeout(() => {
// If we do not set this then the lambda will wait 10secs before completing.
// This is because pg starts a 10sec timer for each new client (see idleTimeoutMillis in https://node-postgres.com/api/pool).
// `callbackWaitsForEmptyEventLoop = false` ensures the invocation ends immediately (https://docs.aws.amazon.com/lambda/latest/dg/nodejs-context.html)
context.callbackWaitsForEmptyEventLoop = false;

run(event)
.then((result) => {
console.log('Returning to client:', JSON.stringify(result));
callback(null, result);
})
.catch((err) => {
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions -- any
console.log(`Error: ${err}`);
callback(err);
});
});
};
run(event)
.then((result) => {
console.log('Returning to client:', JSON.stringify(result));
callback(null, result);
})
.catch((err) => {
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions -- any
console.log(`Error: ${err}`);
callback(err);
});
});
};

export const getApiGatewayHandler = (
run: (event: APIGatewayProxyEvent) => Promise<APIGatewayProxyResult>,
Expand Down

0 comments on commit 02488b7

Please sign in to comment.