Created
January 30, 2015 21:23
-
-
Save SteelPangolin/08880dc2c74b9c26cb5b to your computer and use it in GitHub Desktop.
Get an Amazon Elastic Beanstalk environment's name from inside one of its instances
This file contains 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
{ | |
"Version": "2012-10-17", | |
"Statement": [ | |
{ | |
"Action": [ | |
"ec2:Describe*" | |
], | |
"Effect": "Allow", | |
"Resource": "*" | |
} | |
] | |
} |
This file contains 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
#!/usr/bin/env python | |
import boto.utils | |
import boto.ec2 | |
iid_doc = boto.utils.get_instance_identity()['document'] | |
region = iid_doc['region'] | |
instance_id = iid_doc['instanceId'] | |
ec2 = boto.ec2.connect_to_region(region) | |
instance = ec2.get_only_instances(instance_ids=[instance_id])[0] | |
env = instance.tags['elasticbeanstalk:environment-name'] | |
print(env) |
Thanks for the refinement, @Melvin-mlp.
For those of you who did find this through Google, there's more detail in my blog article on how to find the name of an Elastic Beanstalk environment from inside one of its instances.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To help other people like me who came from google search, there is another way to perform this from your elasticbeanstalk instances without allowing all ec2:Describe actions
EC2-DescribeTags-IAM-policy.json
Get environment name from bash script
get-eb-env-name.sh
Below, the command line to get the environment name with one liner: