Last active
March 1, 2016 16:26
-
-
Save heywbj/da10d99f66df6361db9f to your computer and use it in GitHub Desktop.
Get Elastic beanstalk environment information
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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