- Tomasz Łakomy
AWS Lambda runtimes set a number of default environment variables during initialization of every serverless function.
The following variables are reserved and cannot be set in your function configuration:
_HANDLER- The location of a functions's handler.
_X_AMZN_TRACE_ID- X-Ray tracing header
AWS_REGION- The region the function is running in (we all know it's
AWS_EXECUTION_ENV- The AWS Lambda runtime identifier. Examples:
AWS_LAMBDA_FUNCTION_NAME- The name of the function (which is either "hello world" or IaC randomly generated one, there's no between).
AWS_LAMBDA_FUNCTION_MEMORY_SIZE- The amount of memory allocated to the function (e.g. 1024MB).
AWS_LAMBDA_FUNCTION_VERSION- The version of the function (e.g.
AWS_LAMBDA_INITIALIZATION_TYPE- The initialization type of the function, can be either
AWS_LAMBDA_LOG_GROUP_NAME- The name of the CloudWatch log group.
AWS_LAMBDA_LOG_STREAM_NAME- The name of the CloudWatch stream.
AWS_SESSION_TOKEN- The access keys obtained from the function's execution role. Be careful with those, read SAS-7: Insecure Application Secrets Storage for guidance. This post on Security for AWS Lambda Serverless Applications is also a good place to start.
AWS_LAMBDA_RUNTIME_API- The host and port of the AWS Lambda runtime API, example:
LAMBDA_TASK_ROOT- The path to your Lambda function code
LAMBDA_RUNTIME_DIR- The path to runtime libraries
TZ- The timezone information, e.g.
In addition to that, AWS Lambda runtime sets additional variables that are not reserved and can be extended in your function configuration:
LANG- The language of your function's runtime, e.g.
PATH- The execution path, e.g.
LD_LIBRARY_PATH- The system library path, e.g.
/var/lang/lib:/lib64: /usr/lib64:/var/runtime: /var/runtime/lib:/var/task:/var/task/lib:/opt/lib
AWS_XRAY_CONTEXT_MISSING- Quoting the docs: "For X-Ray tracing, Lambda sets this to
LOG_ERRORto avoid throwing runtime errors from the X-Ray SDK."
AWS_XRAY_DAEMON_ADDRESS- The IP address and port of the X-Ray daemon.
There are also a few runtime-specific environment variables:
NODE_PATH- A node.js env variable, containing node.js library path, e.g.
/opt/nodejs/node14/node_modules: /opt/nodejs/node_modules: /var/runtime/node_modules:/var/runtime:/var/task
PYTHONPATH- The Python library path
GEM_PATH- The Ruby library path
AWS_LAMBDA_DOTNET_PREJIT- Quoting the docs: "For the .NET 3.1 runtime, set this variable to enable or disable .NET 3.1 specific runtime optimizations. Values include