UNPKG

@bitblit/ratchet-epsilon-common

Version:

Tiny adapter to simplify building API gateway Lambda APIS

42 lines 1.69 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'; export class S3EpsilonLambdaEventHandler { _epsilon; constructor(_epsilon) { this._epsilon = _epsilon; } extractLabel(evt, _context) { return 'S3Evt:' + evt.Records[0].eventSource; } handlesEvent(evt) { return LambdaEventDetector.isValidS3Event(evt); } async processEvent(evt, _context) { let rval = null; if (this._epsilon.config && this._epsilon.config.s3 && evt && evt.Records.length > 0) { const finder = evt.Records[0].s3.bucket.name + '/' + evt.Records[0].s3.object.key; const isRemoveEvent = evt.Records[0].eventName && evt.Records[0].eventName.startsWith('ObjectRemoved'); if (isRemoveEvent) { const handler = AwsUtil.findInMap(finder, this._epsilon.config.s3.removeHandlers); if (handler) { rval = await handler(evt); } else { Logger.info('Found no s3 create handler for : %s', finder); } } else { const handler = AwsUtil.findInMap(finder, this._epsilon.config.s3.createHandlers); if (handler) { rval = await handler(evt); } else { Logger.info('Found no s3 remove handler for : %s', finder); } } } return rval; } } //# sourceMappingURL=s3-epsilon-lambda-event-handler.js.map