import boto3
s3=boto3.client('s3')
list=s3.list_objects(Bucket='mert01')['Contents']
list[1:3]

# https://stackoverflow.com/questions/3337912/quick-way-to-list-all-files-in-amazon-s3-bucket
import boto

s3 = boto.connect_s3()
bucket = s3.get_bucket('mert01')
#bl = bucket.list()
#for key in bucket.list():
#    print(key.name)


import itertools
for el in itertools.islice(bl, 0, 3):
    print(el.name)

# len(bl)
i = 0
for key in bucket.list():
    i = i + 1
print(i)


bl2 = bucket.list(prefix="201")
for el in itertools.islice(bl2, 0, 3):
    print(el.name)

# https://stackoverflow.com/questions/10054985/how-to-delete-files-recursively-from-an-s3-bucket#18698235
result = bucket.delete_keys([key.name for key in bl2])
result

"""
Explanation: s3
list all files
End of explanation
"""


!aws configure help

!aws configure list

!cat ~/.aws/config

!export AWS_DEFAULT_REGION=us-west-1
!aws ec2 describe-volumes

"""
Explanation: aws cli
aws configure
End of explanation
"""


!aws iam list-groups

!aws iam list-attached-group-policies --group-name iterative

!aws iam list-users

"""
Explanation: IAM (identity and access management)
Documentation:
http://docs.aws.amazon.com/IAM/latest/UserGuide/getting-started_create-admin-group.html?shortFooter=true#Using_CreateGroup
End of explanation
"""


!awespottr c4.xlarge

!export AWS_DEFAULT_REGION=us-east-2
!aws ec2 describe-spot-price-history --availability-zone "${AWS_DEFAULT_REGION}b" --product-description "Linux/UNIX" --instance-types c4.xlarge --start-time `date -u --date="7 days ago" +'%Y-%m-%dT%H:%M:00'` | jq -r -c '.SpotPriceHistory[] | (.SpotPrice)' | head -n 20

!aws ec2 describe-regions

!aws ec2 describe-availability-zones --region us-east-2

"""
Explanation: Find cheapest prices: awespottr
End of explanation
"""


!aws ec2 describe-images --owners self amazon --filters "Name=root-device-type,Values=ebs" > data/ex_aws01.json

!cat data/ex_aws01.json | head -n 30

!jq '{ami: .Images[].ImageId}' data/ex_aws01.json | head -n 8

!jq '{ami: [.Images[].ImageId]}' data/ex_aws01.json | head -n 5

"""
Explanation: Finding AMIs
End of explanation
"""


