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