In [51]:
import json
In [53]:
def remove_sensitive_info(instance):
'''instance is a dict representing an EC2 instance'''
instance.pop('instanceId', None)
instance.pop('publicDnsName', None)
instance.pop('publicIpAddress', None)
instance['sshAccessInfo']['keyPair'].pop('keyName', None)
instance['account'].pop('accountId', None)
instance['account'].pop('ownerAlias', None)
In [55]:
def main():
d = json.loads(open('unclean_instances.json').read())
instances = d['success']['body']['instances']
map(remove_sensitive_info, instances)
f = open('instances.json', 'w')
f.write(json.dumps(instances, indent=2))
In [56]:
if __name__ == '__main__':
main()