On this page

I’ve been using Amazon AWS quite recently at my new job at Mercury FX, and I love it. I have been converting many functions run from a single application into smaller Lambda functions that I can then schedule and trigger with other tools provided by AWS.

One of the first things I learned about was Environment Variables. They allow you to configure settings for a function without hardcoding them. They look like this in the AWS Console:

Accessing these environment variables is different in every programming language supported by AWS Lambda, as each language uses a native API for retrieving the environment variables instead of introducing a dependency for retrieving environment variables (yay, no need for another dependency). I have used a few languages in AWS Lambda while learning how to use it effectively and decided to create a post summarising how to retrieve environment variables in every language supported by AWS Lambda.

Table of Contents

C#

C#
Environment.GetEnvironmentVariable("NAME_OF_VARIABLE");

Go

Go
import ("os")os.Getenv("NAME_OF_VARIABLE");

Java

Java
System.getenv("NAME_OF_VARIABLE");

Node.js

JavaScript
process.env.NAME_OF_VARIABLE;

Powershell

Ps
$env:NAME_OF_VARIABLE

Python

Python
import osos.environ['NAME_OF_VARIABLE']

Ruby

Ruby
ENV['NAME_OF_VARIABLE']

I hope you found this useful. If I have left something out or made a mistake, please let me know in the comments!

References