100 Days of AWS — Day 24- Boto3 Concepts(Waiter, Meta, and Paginator)

import boto3ec2 = boto3.resource("ec2")instance_id=input("Please enter the instance id: ")
instance=ec2.Instance(instance_id)
print("Starting EC2 instance")
instance.start()
instance.wait_until_running()
print("Your instance is up and running")
wait_until_exists 
wait_until_running
wait_until_stopped
wait_until_terminated'
import boto3ec2 = boto3.client("ec2")instance_id=input("Please enter the instance id: ")
print("Starting EC2 instance")
instance=ec2.start_instances(InstanceIds=[instance_id])
waiter = ec2.get_waiter('instance_running')
waiter.wait(InstanceIds=[instance_id])

print("Your instance is up and running")
import boto3ec2 = boto3.resource("ec2")
ec2_cli = boto3.client("ec2")
instance_id=input("Please enter the instance id: ")
instance=ec2.Instance(instance_id)
print("Starting EC2 instance")
instance.start()
waiter = ec2_cli.get_waiter('instance_running')
waiter.wait(InstanceIds=[instance_id])

print("Your instance is up and running")
>>> import boto3
>>> ec2 = boto3.resource("ec2")
>>> for region in ec2.meta.client.describe_regions()['Regions']:
... print(region['RegionName'])
...
eu-north-1
ap-south-1
eu-west-3
eu-west-2
eu-west-1
ap-northeast-3
ap-northeast-2
ap-northeast-1
sa-east-1
ca-central-1
ap-southeast-1
ap-southeast-2
eu-central-1
us-east-1
us-east-2
us-west-1
us-west-2
import boto3iam_res = boto3.resource("iam")count=1
for user in iam_res.users.all():
print(count, user.name)
count=count+1
python3 test.py |wc -l
145
import boto3iam_client = boto3.client("iam")count=1
for user in iam_client.list_users()['Users']:
print(count, user['UserName'])
count=count+1
python3 test.py |wc -l
100
import boto3iam_client = boto3.client("iam")
paginator = iam_client.get_paginator('list_users')
page_iterator=paginator.paginate()
count=1
for user in page_iterator:
for username in user['Users']:
print(count, username['UserName'])
count+=1
python3 test.py |wc -l
145

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store