Skip to content

Commit

Permalink
Add memory and timeout to lambda table
Browse files Browse the repository at this point in the history
  • Loading branch information
mansurpasha committed Apr 29, 2020
1 parent 20f2dce commit 047dfc1
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/components/resourceTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
import { getStackResources } from "../services/stackResources";
import { lambdaStatisticsModal } from "../modals/lambdaStatisticsModal";
import { lambdaInvokeModal } from "../modals/lambdaInvokeModal";
import { getFunctionMemoryAndTimeout } from "../services/awsLambda";
import { padString } from "../utils/padString";

const contrib = require("blessed-contrib");
const open = require("open");
Expand Down Expand Up @@ -39,6 +41,7 @@ class resourceTable {
[this.funcName] = item.data;
this.fullFuncName = this.getFullFunctionName(this.funcName);
});
this.funcConfigs = {};
this.provider = provider;
this.slsDevToolsConfig = slsDevToolsConfig;
this.lambdasDeploymentStatus = {};
Expand Down Expand Up @@ -161,7 +164,7 @@ class resourceTable {
fg: "green",
label: "<- Lambda Functions ->",
columnSpacing: 1,
columnWidth: [45, 30, 30],
columnWidth: [35, 40, 10, 10, 20],
style: {
border: {
fg: "yellow",
Expand Down Expand Up @@ -254,13 +257,28 @@ class resourceTable {
this.table.data = lambdaFunctionResources.map((lam) => {
const funcName = lam.PhysicalResourceId;
const func = this.lambdaFunctions[funcName];
getFunctionMemoryAndTimeout(this.lambda, funcName).then((config) => {
this.funcConfigs[funcName] = config;
});
let timeout = this.funcConfigs[funcName]
? this.funcConfigs[funcName].timeout
: "?";
let memory = this.funcConfigs[funcName]
? this.funcConfigs[funcName].memory
: "?";
// Max timout is 900 seconds, align values with whitespace
timeout = padString(timeout, 3);
// Max memory is 3008 MB, align values with whitespace
memory = padString(memory, 4);
let funcRuntime = "?";
if (func) {
funcRuntime = func.Runtime;
}
return [
lam.PhysicalResourceId.replace(`${this.program.stackName}-`, ""),
moment(lam.LastUpdatedTimestamp).format("MMMM Do YYYY, h:mm:ss a"),
`${memory} MB`,
`${timeout} secs`,
funcRuntime,
];
});
Expand Down Expand Up @@ -361,7 +379,7 @@ class resourceTable {
}

this.table.setData({
headers: ["logical", "updated", "runtime"],
headers: ["logical", "updated", "memory", "timeout", "runtime"],
data: lambdaFunctionsWithDeploymentIndicator,
});

Expand Down
24 changes: 24 additions & 0 deletions src/services/awsLambda.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
async function getFunctionConfig(lambdaApi, params) {
return lambdaApi
.getFunctionConfiguration(params)
.promise()
.catch(() => null);
}

async function getFunctionMemoryAndTimeout(lambdaApi, funcName) {
const params = { FunctionName: funcName };

const config = await getFunctionConfig(lambdaApi, params);
if (config) {
const details = {
timeout: config.Timeout.toString(),
memory: config.MemorySize.toString(),
};
return details;
}
return null;
}

module.exports = {
getFunctionMemoryAndTimeout,
};
12 changes: 12 additions & 0 deletions src/utils/padString.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Add whitespace to the front of a string until it's at least numCharacters long
function padString(s, numCharacters) {
let result = s;
while (result.length < numCharacters) {
result = ` ${result}`;
}
return result;
}

module.exports = {
padString,
};

0 comments on commit 047dfc1

Please sign in to comment.