Lambda functions support the environment parameter and make it easy to define a key-value pair. But what about getting an object (defined by a module variable eg) into the function's environment?
Quick example of what I'm trying to accomplish in python 3.7:
Terraform:
# variable definition
variable foo {
type = map(any)
default = {
a = "b"
c = "d"
}
}
resource "aws_lambda_function" "lambda" {
.
.
.
environment {
foo = jsonencode(foo)
}
}
and then in my function:
def bar:
for k in os.environ["foo"]:
print(k)
Thanks !
In python, you will have to get json string and convert it to dict:
import json
def bar:
for k in json.loads(os.environ["foo"]):
print(k)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With