UNPKG

@bitblit/epsilon

Version:

Tiny adapter to simplify building API gateway Lambda APIS

56 lines 2.69 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.S3EpsilonLambdaEventHandler = void 0; const common_1 = require("@bitblit/ratchet/common"); const aws_util_1 = require("../util/aws-util"); const aws_1 = require("@bitblit/ratchet/aws"); class S3EpsilonLambdaEventHandler { constructor(_epsilon) { this._epsilon = _epsilon; } extractLabel(evt, context) { return 'S3Evt:' + evt.Records[0].eventSource; } handlesEvent(evt) { return aws_1.LambdaEventDetector.isValidS3Event(evt); } processEvent(evt, context) { return __awaiter(this, void 0, void 0, function* () { 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 = aws_util_1.AwsUtil.findInMap(finder, this._epsilon.config.s3.removeHandlers); if (handler) { rval = yield handler(evt); } else { common_1.Logger.info('Found no s3 create handler for : %s', finder); } } else { const handler = aws_util_1.AwsUtil.findInMap(finder, this._epsilon.config.s3.createHandlers); if (handler) { rval = yield handler(evt); } else { common_1.Logger.info('Found no s3 remove handler for : %s', finder); } } } return rval; }); } } exports.S3EpsilonLambdaEventHandler = S3EpsilonLambdaEventHandler; //# sourceMappingURL=s3-epsilon-lambda-event-handler.js.map