import pprint
p = pprint.PrettyPrinter(indent=4)
p.pprint(x)
or
import pprint
pprint.pformat(x)
import logging
import pprint
logging.info(pprint.pformat(dict))
$ cat monitor_beanstalk.py
#!/bin/python
import boto3
import pprint
pp = pprint.PrettyPrinter(indent=4)
#List all env and status and instances health
client = boto3.client('elasticbeanstalk')
envs = client.describe_environments()['Environments']
#pp.pprint(envs)
for env in envs:
print 'ApplicationName: {} EnvironmentName: {} Health: {} HealthStatus: {} Status: {}'.format(env['ApplicationName'].ljust(30),env['EnvironmentName'].ljust(30),env['Health'].ljust(10),env.get('HealthStatus', 'N/A').ljust(10),env['Status'].ljust(10))
if (env['Health'] != 'Green') or (env.get('HealthStatus', 'N/A') != 'Ok' and env.get('HealthStatus', 'N/A') != 'N/A'):
print '\nProblem'
details = client.describe_environment_health(EnvironmentName=env['EnvironmentName'],AttributeNames=['All'])
#pp.pprint(details)
print details['Causes']
print details['InstancesHealth']
print '\n'