AWS Lambda Environment Variables are a useful way to input configuration values to your AWS Lambda runtime. Especially, when there are configurations that are different in your Development environment compared to your Production environment. Like name of DynamoDB tables or MySQL databases.
Below we discuss how we can retrieve the values of Environment Variables in AWS Lambda using Ruby.
Ruby Code to Access Environment Variables
The code for accessing Environment Variables on AWS Lambda is just the same code for accessing environment variables in your local computer or server.
Here is the code to access environment variables using Ruby.
env_var = ENV['ENVIRONMENT_VARIABLE']
If we want to get the value of an environment variable with the key of DB_HOST
then we will use the code below.