UNPKG

@bitblit/ratchet-epsilon-common

Version:

Tiny adapter to simplify building API gateway Lambda APIS

36 lines 1.43 kB
import { AwsUtil } from '../util/aws-util.js'; import { NoHandlersFoundError } from '../config/no-handlers-found-error.js'; import { LambdaEventDetector } from '@bitblit/ratchet-aws/lambda/lambda-event-detector'; import { Logger } from '@bitblit/ratchet-common/logger/logger'; export class GenericSqsEpsilonLambdaEventHandler { _epsilon; constructor(_epsilon) { this._epsilon = _epsilon; } extractLabel(evt, _context) { return 'SQSEvt:' + evt.Records[0].eventSourceARN; } handlesEvent(evt) { return LambdaEventDetector.isValidSqsEvent(evt); } async processEvent(evt, _context) { let rval = null; if (this._epsilon.config && this._epsilon.config.sqs && evt && evt.Records.length > 0) { const finder = evt.Records[0].eventSourceARN; const handler = AwsUtil.findInMap(finder, this._epsilon.config.sqs.handlers); if (handler) { rval = await handler(evt); } else { Logger.info('Found no SQS handler for : %s', finder); throw new NoHandlersFoundError(); } } return rval; } async processUncaughtError(event, context, err) { Logger.error('Error slipped out to outer edge (SQS). Logging and rethrowing : %s', err, err); throw err; } } //# sourceMappingURL=generic-sqs-epsilon-lambda-event-handler.js.map