---
title: "Getting AWS Lambda Environment Variables in all supported languages — Ivan Kahl"
description: "Every language supported by AWS Lambda reads environment variables through its own native API. Code snippets for each are collected in one place, with no extra dependencies."
url: https://ivankahl.com/blog/getting-aws-lambda-environment-variables-in-all-supported-languages/
published: 2019-10-29T00:00:00.000Z
tags:
  - "AWS"
  - "Lambda"
  - "Serverless"
  - "Guides"
---

29 Oct 2019 · 1 min read

# Getting AWS Lambda Environment Variables in all supported languages

Every language supported by AWS Lambda reads environment variables through its own native API. Code snippets for each are collected in one place, with no extra dependencies.

> Lambda now supports Docker images allowing you to use almost any language in a Lambda function. However, below, you’ll find instructions on accessing environment variables in some popular programming languages.

I’ve been using Amazon AWS quite recently at my new job at [Mercury FX](https://www.mercury-fx.com/), 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#](https://ivankahl.com/blog/getting-aws-lambda-environment-variables-in-all-supported-languages/#c-)
-   [Go](https://ivankahl.com/blog/getting-aws-lambda-environment-variables-in-all-supported-languages/#go)
-   [Java](https://ivankahl.com/blog/getting-aws-lambda-environment-variables-in-all-supported-languages/#java)
-   [Node.js](https://ivankahl.com/blog/getting-aws-lambda-environment-variables-in-all-supported-languages/#node-js)
-   [Powershell](https://ivankahl.com/blog/getting-aws-lambda-environment-variables-in-all-supported-languages/#powershell)
-   [Python](https://ivankahl.com/blog/getting-aws-lambda-environment-variables-in-all-supported-languages/#python)
-   [Ruby](https://ivankahl.com/blog/getting-aws-lambda-environment-variables-in-all-supported-languages/#ruby)

## C#

```csharp
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 os
os.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

-   [https://stackoverflow.com/questions/41094954/accessing-aws-lambda-environment-variables-in-java-code](https://stackoverflow.com/questions/41094954/accessing-aws-lambda-environment-variables-in-java-code)
-   [https://docs.aws.amazon.com/lambda/latest/dg/go-programming-model-env-variables.html](https://docs.aws.amazon.com/lambda/latest/dg/go-programming-model-env-variables.html)
-   [https://fitch.tech/2019/05/29/aws-lambda-for-powershell-encrypted-environment-variables/](https://fitch.tech/2019/05/29/aws-lambda-for-powershell-encrypted-environment-variables/)
-   [https://stackoverflow.com/questions/40937512/how-to-access-an-aws-lambda-environment-variable-from-python](https://stackoverflow.com/questions/40937512/how-to-access-an-aws-lambda-environment-variable-from-python)
-   [https://www.honeybadger.io/blog/using-ruby-on-aws-lamba/](https://www.honeybadger.io/blog/using-ruby-on-aws-lamba/)

Tags: [AWS](https://ivankahl.com/blog/tags/aws/), [Lambda](https://ivankahl.com/blog/tags/lambda/), [Serverless](https://ivankahl.com/blog/tags/serverless/), [Guides](https://ivankahl.com/blog/tags/guides/)
