Skip to content

Instantly share code, notes, and snippets.

@heywbj
Last active March 1, 2016 16:26
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save heywbj/da10d99f66df6361db9f to your computer and use it in GitHub Desktop.
Save heywbj/da10d99f66df6361db9f to your computer and use it in GitHub Desktop.
Get Elastic beanstalk environment information
import boto.utils
import boto.beanstalk
good_statuses = ('Launching', 'Updating', 'Ready')
def get_eb_environment_description():
identity_document = boto.utils.get_instance_identity()['document']
connection = boto.beanstalk.connect_to_region(identity_document['region'])
envs = (e for e in
connection.describe_environments()
['DescribeEnvironmentsResponse']
['DescribeEnvironmentsResult']
['Environments']
)
for env in envs:
if env['Status'] not in good_statuses:
continue
resources = (
connection.describe_environment_resources(
environment_name=env['EnvironmentName']
)
['DescribeEnvironmentResourcesResponse']
['DescribeEnvironmentResourcesResult']
['EnvironmentResources']
)
for instance in resources['Instances']:
if instance['Id'] == identity_document['instanceId']:
return env
return None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment