Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Chalice: Reading lambda evironment variables in Python

I need to access environment variables I created in AWS Lambda from my Chalice Python code but I am unable to find examples that make sense.

Thoughts?

I am using Python 3.6.

like image 872
Not a machine Avatar asked Apr 13 '26 20:04

Not a machine


1 Answers

You just use the os environment variable access.

import os
print(os.environ["MY_VARIABLE"])

If your question is how to set the environment variables in Chalice. You set them in the Chalice config:

.chalice/config.json

{
  "version": "2.0",
  "app_name": "gtf",
  "stages": {
    "dev": {
      "environment_variables": {
          "MY_VARIABLE": "MY_VALUE"
      }
    }
  }
}

https://chalice.readthedocs.io/en/latest/topics/configfile.html

like image 89
Michael Robellard Avatar answered Apr 17 '26 03:04

Michael Robellard



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!