How can I use environmental variables on AWS Lambda?

Viewed 23363

I'm writing an application which I want to run as an AWS Lambda function but also adhere to the Twelve-Factor app guidelines. In particular Part III. Config which requires the use of environmental variables for configuration.

However, I cannot find a way to set environmental variables for AWS Lambda instances. Can anyone point me in the right direction?

If it isn't possible to use environmental variables can you please recommend a way to use environmental variables for local development and have them transformed to a valid configuration system that can be accessed using the application code in AWS.

Thanks.

6 Answers

I know it has been a while, but I didn't see a solution that works from the AWS Lambda console.

STEPS:

  1. In your AWS Lambda Function Code, look for "Environment variables", and click on "Edit";
  2. For the "Key", type "LD_LIBRARY_PATH";
  3. For the "Value", type "/opt/python/lib".

Look at this screenshot for the details.

The #3 assumes that you are using Python as your runtime environment, and also that your uploaded Layer has its "lib" folder in the following structure: python/lib

This solution works for the error: /lib/x86_64-linux-gnu/libz.so.1: version 'ZLIB_1.2.9' not found assuming the correct libray file is put in the "lib" folder and that the environment variable is set like above.

PS: If you are unsure about the #3 path, just look for the error in your console, and you will be able to see where your "lib" folder for your layer is at runtime.

Related