Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.