Derek
Derek

Reputation: 1

How to retrieve environment variables defined on an AWS Lambda function

I have a function where I want to list lambda environment variables but I cannot get the values just the names:

import boto3

l_client = boto3.client('lambda')
func_resp = l_client.get_function(FunctionName='arn:aws:lambda:us-west-1:111111111111:function:RedshiftPut')
env_vars = func_resp['Configuration']['Environment']['Variables']
for env_var in env_vars:
    print(env_var) 

This gives me the environment name but not the value.

I can get the values using a name from the list:

print(env_vars['FILE_NAME']) #from the list I got from print(env_var) 

How do I get the values?

Upvotes: 0

Views: 1905

Answers (1)

John Rotenstein
John Rotenstein

Reputation: 269284

Your env_vars is a Python dictionary in the format of:

{'Key11': 'Value1', 'Key2': 'Value2'}

You could show the values like this:

for key in env_vars:
    print(key, env_vars[key])

Basically, the for loop returns provides the key. You can then use the key with the dictionary to return the value: env_vars[key]

You can also access them together like this:

for key, value in env_vars:
    print(key, value)

Upvotes: 2

Related Questions