@multicloud/sls-aws
Version:
Amazon AWS specific middleware and components for Serverless @multicloud.
57 lines (56 loc) • 2.08 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
};
Object.defineProperty(exports, "__esModule", { value: true });
require("reflect-metadata");
const sls_core_1 = require("@multicloud/sls-core");
const inversify_1 = require("inversify");
/**
* Implementation of Cloud Context for AWS Lambda
*/
let AwsContext = class AwsContext {
/**
* Initializes new AwsContext, injects runtime arguments of AWS Lambda.
* Sets runtime parameters from original arguments
* @param args Runtime arguments for AWS Lambda
*/
constructor(args) {
this.providerType = "aws";
this.runtime = {
event: args[0],
context: args[1],
callback: args[2],
};
this.id = this.runtime.context.awsRequestId;
// AWS has a single incoming event source
this.event = this.runtime.event;
}
/**
* Send response from AWS Lambda
* @param body Body of response
* @param status Status code of response
*/
send(body, status = 200) {
if (this.res) {
this.res.send(body, status);
}
this.done();
}
flush() {
if (this.res) {
this.res.flush();
}
}
};
AwsContext = __decorate([
inversify_1.injectable(),
__param(0, inversify_1.inject(sls_core_1.ComponentType.RuntimeArgs))
], AwsContext);
exports.AwsContext = AwsContext;