Skip to content

Instantly share code, notes, and snippets.

@garnaat
Last active December 23, 2015 18:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save garnaat/6675449 to your computer and use it in GitHub Desktop.
Save garnaat/6675449 to your computer and use it in GitHub Desktop.
Call EC2 DescribeInstances using botocore
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