Skip to content

Commit 5864736

Browse files
author
100daysofdevops
committed
adding waiter, meta and paginator code for boto3
1 parent f752042 commit 5864736

5 files changed

Lines changed: 46 additions & 0 deletions

File tree

boto3/boto3_meta.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
>>> import boto3
2+
>>> ec2 = boto3.resource("ec2")
3+
>>> for region in ec2.meta.client.describe_regions()['Regions']:
4+
... print(region['RegionName'])

boto3/ec2_client_waiter.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import boto3
2+
3+
ec2 = boto3.client("ec2")
4+
5+
instance_id=input("Please enter the instance id: ")
6+
print("Starting EC2 instance")
7+
instance=ec2.start_instances(InstanceIds=[instance_id])
8+
waiter = ec2.get_waiter('instance_running')
9+
waiter.wait(InstanceIds=[instance_id])
10+
print("Your instance is up and running"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import boto3
2+
3+
ec2 = boto3.resource("ec2")
4+
ec2_cli = boto3.client("ec2")
5+
6+
instance_id=input("Please enter the instance id: ")
7+
instance=ec2.Instance(instance_id)
8+
print("Starting EC2 instance")
9+
instance.start()
10+
waiter = ec2_cli.get_waiter('instance_running')
11+
waiter.wait(InstanceIds=[instance_id])
12+
print("Your instance is up and running")

boto3/ec2_resource_waiter.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import boto3
2+
3+
ec2 = boto3.resource("ec2")
4+
5+
instance_id=input("Please enter the instance id: ")
6+
instance=ec2.Instance(instance_id)
7+
print("Starting EC2 instance")
8+
instance.start()
9+
instance.wait_until_running()
10+
print("Your instance is up and running")
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import boto3
2+
3+
iam_client = boto3.client("iam")
4+
paginator = iam_client.get_paginator('list_users')
5+
page_iterator=paginator.paginate()
6+
count=1
7+
for user in page_iterator:
8+
for username in user['Users']:
9+
print(count, username['UserName'])
10+
count+=1

0 commit comments

Comments
 (0)