I am trying to get a list of all the EBS volumes in an AWS account. I'm using Python 3 and boto3 version 1.10.34.
I found this post with some suggestions but neither of them work.
I'm setting the ec2_client like this:
import boto3
session = boto3.Session(profile_name=aws_account,region_name='us-east-1')
ec2_client = session.client('ec2')
If I try volumes = ec2_client.volumes.all() I get back AttributeError: 'EC2' object has no attribute 'volumes'.
If I try volumes = ec2_client.get_all_volumes()I get back AttributeError: 'EC2' object has no attribute 'get_all_volumes'.
How can I do this correctly?
I suggest you use
paginatorwhen you need to describe "all" volumes.If you have more than 1000 volumes,
describe_volumes()will not describe all volumes, just the first 1000.Let me quote the reference documentation below.
Reference: https://boto3.amazonaws.com/v1/documentation/api/latest/guide/paginators.html
See an snippet below: