Skip to content

Instantly share code, notes, and snippets.

@jweyrich
Last active June 16, 2022 01:20
Show Gist options
  • Save jweyrich/42ea5c7dae4749b306ed5f919b81fc82 to your computer and use it in GitHub Desktop.
Save jweyrich/42ea5c7dae4749b306ed5f919b81fc82 to your computer and use it in GitHub Desktop.
Python3 script to export all parameters stored in the AWS Systems Manager Parameter Store
#!/usr/bin/env python3
#
# Author: Jardel Weyrich <jweyrich at gmail dot com>
#
# How to run:
# aws-vault exec <profile> -- python3 aws-ssm-export-all-parameters.py > result.json
#
import boto3
import os
import sys
import json
def get_account_id():
client = boto3.client('sts')
response = client.get_caller_identity()
return response.get('Account')
def get_parameters():
client = boto3.client('ssm')
paginator = client.get_paginator('get_parameters_by_path')
pages = paginator.paginate(Path='/', Recursive=True, WithDecryption=True)
result = []
for page in pages:
result += [{
'name': it.get('Name'),
'type': it.get('Type'),
'value': it.get('Value')
} for it in page.get('Parameters')]
return result
def main():
region = os.environ.get('AWS_REGION', 'us-east-1')
account_id = get_account_id()
print(f'REGION={region}, ACCOUNT={account_id}', file=sys.stderr)
print('', file=sys.stderr)
parameters = get_parameters()
output = json.dumps({'parameters': parameters})
print(output)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment