import boto3
s3_my_resource = boto3.resource('s3')
for bucket in s3_my_resource.buckets.all():
print(bucket.name)
Sample Code around EC2 instances
import boto3
ec2_resource = boto3.resource('ec2')
ec2_instances = ec2_resource.instances.all()
for instance in ec2_instances:
print(instance.instance_id + "==> "+ instance.state['Name'])
# Stop the machines if they are running
if(instance.state['Name'] == 'running'):
instance.stop()
# Terminate the machines if they are stopped
if(instance.state['Name'] == 'stopped'):
instance.terminate()
# Refer Here for creating Instance https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ec2.html#EC2.ServiceResource.create_instances