Aws-cli: AWS s3 get-bucket-location return null

Created on 12 Jan 2019  路  3Comments  路  Source: aws/aws-cli

Hi,
I have say three buckets in my AWS account.
When I run the below command
aws s3api get-bucket-location --bucket <my_bucket_name>
I get
{
"LocationConstraint": null
}

On checking the same bucket in AWS Console, the bucket region is US East (N. Virginia)

closing-soon guidance s3api

Most helpful comment

For future reference if one need to retrieve the region of the bucket(which seems to be the case when using get-bucket-location, one can use jq to set the region by default:

aws s3api get-bucket-location --bucket "<my_bucket_name>" \
| jq -r '.LocationConstraint // "us-east-1"'

Or directly the query option(using JMESPath):

aws s3api get-bucket-location \
  --bucket "<my_bucket_name>" \
  --query="[?LocationConstraint]|'us-east-1'" \
  --output=text

Beware that the double quotes are required for the query to work.

All 3 comments

@abhishekbedi1432 - Thank you for reaching out. The location constraint will be null for buckets located in US Standard region. The CLI uses the values in the region column for the --region parameter. So for S3's US Standard, you need to use us-east-1 as the region. When working with this bucket you'll need to use:

aws s3api get-bucket-location --bucket <my_bucket_name> --region us-east-1

The following documentation provides a list of region names with their corresponding regions: http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region. If this does not answer your question, please reply with the sanitized output from using --debug so I can dig a little deeper into the problem.

This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.

For future reference if one need to retrieve the region of the bucket(which seems to be the case when using get-bucket-location, one can use jq to set the region by default:

aws s3api get-bucket-location --bucket "<my_bucket_name>" \
| jq -r '.LocationConstraint // "us-east-1"'

Or directly the query option(using JMESPath):

aws s3api get-bucket-location \
  --bucket "<my_bucket_name>" \
  --query="[?LocationConstraint]|'us-east-1'" \
  --output=text

Beware that the double quotes are required for the query to work.

Was this page helpful?
0 / 5 - 0 ratings