Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Get all env variables for all AWS Lamda functions in a CloudFormation/SAM stack
#! /usr/bin/env python
# Use at your own risk and reward.
# requires boto3 to be installed
# example `./ MyStack > vars.json`
import sys, json
import boto3
if len(sys.argv) == 1:
print('CloudFormation stack required')
cloudformation_client = boto3.client('cloudformation')
lambda_client = boto3.client('lambda')
page = {}
# Grab stack from AWS
stack_resources = cloudformation_client.list_stack_resources(
except Exception as e:
# Grab environment vars from each lambda in the stack
for resource in stack_resources['StackResourceSummaries']:
lambda_config = lambda_client.get_function_configuration(
if 'Environment' in lambda_config and 'Variables' in lambda_config['Environment']:
page[resource['LogicalResourceId']] = lambda_config['Environment']['Variables']
# Print to console
print(json.dumps(page, indent=2))

This comment has been minimized.

Copy link
Owner Author

@singledigit singledigit commented Oct 20, 2020

I use theis script to generate my environment file for using AWS SAM sam local invoke -n environmant-vars.json. As described here:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.