Skip to content

Instantly share code, notes, and snippets.

@SteelPangolin
Created January 30, 2015 21:23
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SteelPangolin/08880dc2c74b9c26cb5b to your computer and use it in GitHub Desktop.
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
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"ec2:Describe*"
],
"Effect": "Allow",
"Resource": "*"
}
]
}
#!/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)
@SteelPangolin
Copy link
Author

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