- Newest
- Most votes
- Most comments
My previous response was a fast question, the negative vote was unexpected. Based on what you mentioned before to another answer I was able to create a Powershell script that I hope could be useful in your case. Assuming you define a variable name region
Set-Variable -name region -Value "us-west-2"
Running the following script should give you the bucket names
aws s3api list-buckets --output json | jq .Buckets[].Name |
foreach-object {
Set-Variable -name bname -value $_
aws s3api get-bucket-location --bucket $_
} |
foreach-object{ if($region -eq $_) { Write-Output $bName } }
Take care and stay safe, Best regards,
Igvir
Not possible with aws "aws s3 ls" or "aws s3api list-buckets"
I'm open to any alternatives, as long as I don't have to query bucket-by-bucket for the region of each one.
Here is a bash answer to this question. you need to use aws s3api get-bucket-location --bucket xxxxx to get the region as documented here.
for bucket in $(aws s3api list-buckets | jq '.Buckets | .[].Name' | sed 's/"//g' ) ; do
location=$(aws s3api get-bucket-location --bucket $bucket | jq '.LocationConstraint' | sed 's/null/us-east-1/g' | sed 's/"//g')
echo $bucket $location
done
Hello According to the AWS Command Line Interface reference, you have the option to use global parameters.
Did you try global parameter --region?
aws s3api list-buckets --region "us-east-2"
It has the exact same output as without
--region
as S3 API is global (although buckets are regional).
Relevant content
- asked 4 months ago
- Accepted Answerasked 9 months ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 8 months ago
This seems to be the only solution AFAIK. It's very unfortunate that we need to call
get-bucket-location
for each bucket. If only AWS could include the region in thelist-buckets
response this could be avoided.I agree AWS could include the region in the list-buckets response.