def list_public_snapshots()

in source/remediation_runbooks/scripts/GetPublicEBSSnapshots.py [0:0]


def list_public_snapshots(account_id):
    ec2 = connect_to_ec2(boto_config)
    control_token = 'start'
    try:

        public_snapshot_ids = []

        while control_token:

            if control_token == 'start': # needed a value to start the loop. Now reset it
                control_token = ''

            kwargs = {
                'MaxResults': 100, 
                'OwnerIds': [ account_id ],
                'RestorableByUserIds': [ 'all' ]
            }
            if control_token:
                kwargs['NextToken'] = control_token
                
            response = ec2.describe_snapshots(
                        **kwargs
                )
        
            for snapshot in response['Snapshots']:
                public_snapshot_ids.append(snapshot['SnapshotId'])

            if 'NextToken' in response:
                control_token = response['NextToken']
            else:
                control_token = ''

        return public_snapshot_ids
        
    except Exception as e:
        print(e)
        exit('Failed to describe_snapshots')