-
Notifications
You must be signed in to change notification settings - Fork 865
S3 Client not Exposing HeadBucket #3178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
In case anyone is inpatient like me, I've created this extension method using reflection to access the HeadBucketAsync() method. static class AmazonS3ClientExtension
{
#pragma warning disable S3011 // Reflection should not be used to increase accessibility of classes, methods, or fields
static readonly MethodInfo _headBucketAsyncMethod = typeof(AmazonS3Client)
.GetMethod("HeadBucketAsync", BindingFlags.Instance | BindingFlags.NonPublic)!;
static readonly FieldInfo _httpClientResponseDataHeaderField = typeof(HttpClientResponseData)
.GetField("_headers", BindingFlags.NonPublic | BindingFlags.Instance)!;
#pragma warning restore S3011 // Reflection should not be used to increase accessibility of classes, methods, or fields
static public Task<HeadBucketResponse> HeadBucketAsync(this AmazonS3Client client, HeadBucketRequest request, CancellationToken cancellationToken = default)
=> (Task<HeadBucketResponse>)_headBucketAsyncMethod.Invoke(client, [request, cancellationToken])!;
// Use reflection to get the region from the response-headers
static public string? GetRegionFromResponseHeader(this AmazonServiceException ex)
{
var responseEx = ex.InnerException as HttpErrorResponseException;
var responseData = responseEx?.Response as HttpClientResponseData;
var headers = _httpClientResponseDataHeaderField.GetValue(responseData) as Dictionary<string, string>;
string? region = headers?.GetValueOrDefault("x-amz-bucket-region");
return region;
}
} |
PR #3712 merged to |
Changes released in AWSSDK.S3 version 3.7.415.23. |
Comments on closed issues are hard for our team to see. |
Discussed in #3175
Originally posted by omamoo February 7, 2024
Hello all,
I'm writing a code that uploading content to S3 bucket that resides at different account, i.e. I have a cross account scenario of uploading content to S3.
While writing the code I used
GetBucketLocation
API call to determine the bucket location, however on cross account scenario theGetBucketLocation
fails since I'm not the bucket owner, in addition, I saw on AWS documentation that their recommendation is to useHeadBucket
API call, however the SDK does not expose this API call and defined this call asinternal
.Here is a snapshot from the SDK code:
Can we make this public for use?
The text was updated successfully, but these errors were encountered: