Issue
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 !
Solution
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)
Answered By - Marcin Answer Checked By - Katrina (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.