-
Notifications
You must be signed in to change notification settings - Fork 4
/
get_eb_environment_name
executable file
·38 lines (30 loc) · 1.08 KB
/
get_eb_environment_name
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python
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
env_descr = get_eb_environment_description()
print env_descr['EnvironmentName']