I have a nodejs function deployed as AWS lambda function and in this code:
import os from 'os';
const uptime = os.uptime();
const totalMem = os.totalmem() / 1024 / 1024;
What exactly is uptime
and totalMem
referring to?
Do they refer to information about the uptime of lambda function itself and memory allocated to the lambda function itself?
or do they refer to the virtual machine / container that hosts the lambda function?
2
Answers
When you use the os module in a Node.js application running inside an AWS Lambda function, the uptime and totalMem values will refer to the underlying container that is executing your Lambda function.
uptime: The os.uptime() function returns the number of seconds the system (container in the Lambda case) has been running. In the context of a Lambda function, this could be seen as the container uptime, not the Lambda function itself.
totalMem: The os.totalmem() function returns the total amount of system memory (in bytes) available in the container running your Lambda function. This value may be larger than the memory you've allocated to your Lambda function, as it represents the total memory available in the container.
Keep in mind that these values do not directly represent the Lambda function's uptime or allocated memory. To find the memory allocated to a Lambda function, you can use the AWS_LAMBDA_FUNCTION_MEMORY_SIZE environment variable within your Lambda code:
This value will give you the memory (in MB) allocated to your Lambda function as configured in your function settings.
These methods shows VM or Container’s values. (os)
If you want to see node server process’ values for example, you can use below;