aws / aws/aws-tools-for-powershell
Get-S3HeadBucket Returns Error When Shell Region Is Different From Bucket Region
- Dominant language
- C#
- Stars
- 298
- Forks
- 102
- Avg merge
- 7d 17m
- Merged PRs (30d)
- 2
Description
### Describe the bug
When I use the Get-S3HeadBucket cmdlet to retrieve the region of the bucket, the cmdlet will throw errors when the bucket region is different from my shell region. I must use the -Region parameter to match the bucket region for the cmdlet to return result.
Here's the error when bucket is in us-east-1:
`Get-S3HeadBucket: Error making request with Error Code MovedPermanently and Http Status Code MovedPermanently. No further error information was returned by the service.`
Here's the error when bucket is in a different region other than us-east-1:
`Get-S3HeadBucket: Error making request with Error Code BadRequest and Http Status Code BadRequest. No further error information was returned by the service.`
### Regression Issue
- [ ] Select this option if this issue appears to be a regression.
### Expected Behavior
According to the documentation, I should be able to use the Get-S3HeadBucket regardless of the region.
Here's the quote from GetBucket API:
_"You can make a HeadBucket call on any bucket name to any Region in the partition, and regardless of the permissions on the bucket, you will receive a response header with the correct bucket location so that you can then make a proper, signed request to the appropriate Regional endpoint"_
I have also verified aws cli version `aws s3api head-bucket `actually works fine, but not the powershell version `Get-S3HeadBucket`.
### Current Behavior
Get-S3HeadBucket cmdlet does not return result whenever's the caller's resolved region is not the same as the bucket's region.
Here's the error when bucket is in us-east-1 and caller is not in us-east-1:
`Get-S3HeadBucket: Error making request with Error Code MovedPermanently and Http Status Code MovedPermanently. No further error information was returned by the service.`
Here's the error when bucket is in a different region other than us-east-1:
`Get-S3HeadBucket: Error making request with Error Code BadRequest and Http Status Code BadRequest. No further error information was returned by the service.`
### Reproduction Steps
```
# Assuming bucket is in ap-southeast-5 and shell region is set to ap-southeast-1
$_region = 'ap-southeast-1'
$_bucket_name = 'my-bucket-12345'
Set-DefaultAWSRegion $_region
Get-S3HeadBucket $_bucket_name
Get-S3HeadBucket: Error making request with Error Code BadRequest and Http Status Code BadRequest. No further error information was returned by the service.
```
### Possible Solution
_No response_
### Additional Information/Context
_No response_
### AWS Tools for PowerShell version used
```
ModuleType Version PreRelease Name ExportedCommands
---------- ------- ---------- ---- ----------------
Binary 5.0.141 AWS.Tools.S3 {Add-S3PublicAccessBlock, Copy-S3Object, Get-S3ACL, Get-S3Bucket…}
```
### PowerShell version used
```
Name Value
---- -----
PSVersion 7.5.4
PSEdition Core
GitCommitId 7.5.4
OS Darwin 25.2.0 Darwin Kernel Version 25.2.0: Tue Nov 18 21:09:34 PST 2025; root:xnu-12377.61.12~1/RELEASE_X86_64
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
```
### Operating System and version
macOS Tahoe
Contributor guide
Research direction
Start at the Get-S3HeadBucket cmdlet and reproduce the request with a shell region different from the bucket region, using the provided ap-southeast-5 and ap-southeast-1 example. Compare its behavior with aws s3api head-bucket; done means the cmdlet returns the bucket location without requiring -Region to match, while preserving normal behavior for matching regions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, csharp, powershell
- Domain
- api, cloud
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100