PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, August 21, 2022

[FIXED] How to get a Terraform object into an AWS Lambda environment

 August 21, 2022     amazon-web-services, aws-lambda, environment-variables, python, terraform     No comments   

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)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing