UNPKG

@bitblit/ratchet-epsilon-common

Version:

Tiny adapter to simplify building API gateway Lambda APIS

32 lines 1.24 kB
import { Logger } from '@bitblit/ratchet-common/logger/logger'; import { AwsUtil } from '../util/aws-util.js'; import { LambdaEventDetector } from '@bitblit/ratchet-aws/lambda/lambda-event-detector'; import { NoHandlersFoundError } from '../config/no-handlers-found-error.js'; export class GenericSnsEpsilonLambdaEventHandler { _epsilon; constructor(_epsilon) { this._epsilon = _epsilon; } extractLabel(evt, _context) { return 'SNSEvt:' + evt.Records[0].EventSource; } handlesEvent(evt) { return LambdaEventDetector.isValidSnsEvent(evt); } async processEvent(evt, _context) { let rval = null; if (this._epsilon.config && this._epsilon.config.sns && evt && evt.Records.length > 0) { const finder = evt.Records[0].Sns.TopicArn; const handler = AwsUtil.findInMap(finder, this._epsilon.config.sns.handlers); if (handler) { rval = await handler(evt); } else { Logger.info('Found no SNS handler for : %s', finder); throw new NoHandlersFoundError(); } } return rval; } } //# sourceMappingURL=generic-sns-epsilon-lambda-event-handler.js.map