Last active
December 23, 2015 18:19
-
-
Save garnaat/6675449 to your computer and use it in GitHub Desktop.
Call EC2 DescribeInstances using botocore
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 botocore.session | |
session = botocore.session.get_session() | |
ec2 = session.get_service('ec2') | |
operation = ec2.get_operation('DescribeInstances') | |
endpoint = ec2.get_endpoint('us-west-2') | |
# Calling with no parameters will return all instances | |
# associated with this account in this region. | |
http_response, data = operation.call(endpoint) | |
# You could also limit the results to only certain | |
# instances by passing a list of ID's you want returned. | |
http_response, data = operation.call(endpoint, instance_ids=['i-12345678']) | |
# Finally, you can use filters to further restrict | |
# the results. | |
http_response, data = operation.call(endpoint, filters=[{'Name':'instance-state-name', 'Values':['running']}]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment