UNPKG

@faceteer/cdk

Version:

CDK 2.0 constructs and helpers that make composing a Lambda powered service easier.

32 lines (31 loc) 1.33 kB
import { AsyncHandler, HandlerDefinition, HandlerTypes } from './handler'; import type { SnsEventSourceProps } from 'aws-cdk-lib/aws-lambda-event-sources'; import type { SNSEvent, SNSHandler } from 'aws-lambda'; import { InvalidMessage, ValidatedMessage } from './message'; export interface NotificationHandlerDefinition extends HandlerDefinition { /** The name of the function */ name: string; /** The name of the SNS topic that the function is subscribed to */ topicName: string; /** An optional filter policy for the function */ filterPolicy?: SnsEventSourceProps['filterPolicy']; } export interface NotificationHandlerOptions<T> extends NotificationHandlerDefinition { validator?: (messageBody: any) => T; } export type NotificationHandlerWithDefinition = SNSHandler & { type: HandlerTypes.Notification; definition: NotificationHandlerDefinition; }; export type NotificationEvent<T> = SNSEvent & { /** * Messages that have been validated */ ValidMessages: ValidatedMessage<T>[]; /** * Messages that failed to validate */ InvalidMessages: InvalidMessage[]; }; export declare function NotificationHandler<T = unknown>(options: NotificationHandlerOptions<T>, handler: AsyncHandler<NotificationEvent<T>, void>): NotificationHandlerWithDefinition; export {};