If someone gives me an S3 url with a bucket and an object, but I don't know which account owns the bucket, how can I determine which credentials to present in order to gain access to the object, assuming I have access to hundreds of AWS accounts, but I just don't know which one to look in?
2 Answers
I would simply ask them what account it is ;)
Otherwise if you can’t tell from the bucket name you will have to list buckets from each account and see if your bucket is there.
Simple shell script parsing ~/.aws/credentials
and running aws --profile ${PROFILE} s3 ls
should do. Assuming you’ve got CLI credentials for each account in there.
However before going through all that I would ask them what account it is first.
Using the AWS CLI login to each account and run aws s3 ls
and save it to a file. I would name the files using an account key or something else that uniquely identifies each AWS account you have. Then you can grep
those files for a bucket name and find which account it belonged to.