-
Notifications
You must be signed in to change notification settings - Fork 727
Expand file tree
/
Copy pathlambda.ts
More file actions
33 lines (28 loc) · 1.2 KB
/
lambda.ts
File metadata and controls
33 lines (28 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import middy from '@middy/core';
import type { MiddlewareObj } from '@middy/core';
import { logger, setContext } from '@aws-github-runner/aws-powertools-util';
import { captureLambdaHandler, tracer } from '@aws-github-runner/aws-powertools-util';
import { Context } from 'aws-lambda';
import { sync } from './syncer/syncer';
// Type assertion helper for AWS PowerTools middleware compatibility with Middy v7
const asMiddleware = <TEvent, TResult>(
middleware: ReturnType<typeof captureLambdaHandler>,
): MiddlewareObj<TEvent, TResult, Error, Context> => middleware as MiddlewareObj<TEvent, TResult, Error, Context>;
// eslint-disable-next-line
async function handleSync(event: any, context: Context): Promise<void> {
setContext(context, 'lambda.ts');
logger.logEventIfEnabled(event);
try {
await sync();
} catch (e) {
if (e instanceof Error) {
logger.warn(`Ignoring error: ${e.message}`);
}
logger.debug('Ignoring error', { error: e });
}
}
// Export handler with AWS PowerTools middleware
const powertoolsMiddleware = captureLambdaHandler(tracer);
export const handler = powertoolsMiddleware
? middy(handleSync).use(asMiddleware<unknown, void>(powertoolsMiddleware))
: handleSync;