sls-dev-tools
Version:
The Dev Tools for the Serverless World
54 lines (45 loc) • 1.69 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _abbreviateFunction = require("../../../../utils/abbreviateFunction");
class NoDefaultTimeout {
constructor(AWS, stackName, stackFunctions, SLS) {
this.name = "no-default-timeout";
this.AWS = AWS;
this.stackName = stackName;
this.stackFunctions = stackFunctions;
this.result = false;
this.defaultTimeoutAWS = 3;
this.defaultTimeoutServerlessFramework = 6;
this.failingResources = [];
this.SLS = SLS;
this.failureMessage = "The following functions have their timeout set as default.";
this.rulePage = "See (https://theodo-uk.github.io/sls-dev-tools/docs/no-default-timeout) for impact and how to to resolve.";
}
hasDefaultTimeout(lambdaFunction) {
const shortenedName = (0, _abbreviateFunction.abbreviateFunction)(lambdaFunction.FunctionName, this.stackName);
return [this.defaultTimeoutAWS, this.defaultTimeoutServerlessFramework].includes(lambdaFunction.Timeout) && !this.SLS.getTimeout(shortenedName);
}
async run() {
try {
const defaultTimeoutFuntions = this.stackFunctions.reduce((acc, current) => this.hasDefaultTimeout(current) ? [...acc, current] : acc, []);
this.failingResources = defaultTimeoutFuntions.map(lambda => ({
arn: lambda.FunctionArn,
timeout: lambda.Timeout
}));
if (defaultTimeoutFuntions.length > 0) {
this.result = false;
} else {
this.result = true;
}
} catch (e) {
console.error(e);
this.result = false;
}
return this.result;
}
}
var _default = NoDefaultTimeout;
exports.default = _default;