Skip to content

Get-S3HeadBucket Returns Error When Shell Region Is Different From Bucket Region #413

@siriuschan9

Description

@siriuschan9

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions