What is JMESPath `search()` on paginators?
AdvancedConceptboto3 & AWS automation
Answer
Page iterators support .search(expression), which applies a JMESPath query across all pages and yields matching items, the same query language as aws --query.
pages = ec2.get_paginator("describe_instances").paginate()
for iid in pages.search("Reservations[].Instances[?State.Name=='running'][].InstanceId"):
print(iid)
It is concise for extraction, but plain Python is easier to debug once the logic has conditions on tags.
More on boto3 & AWS automation
What is the difference between a boto3 Session, client and resource?BeginnerHow does boto3 find credentials?BeginnerHow does boto3 decide the region, and what is the gotcha with `AWS_REGION`?AdvancedWhy do you need paginators, and how do you use them?BeginnerHow do you handle errors from boto3?BeginnerWhat are waiters, and why use them instead of `sleep` loops?Intermediate