-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
s3: error for out of region bucket - 301 response missing Location header #356
Comments
Hi @ncw thanks for submitting this bug. The SDK should not be retrying request when they error with this request. The 301 error returned is due to the request being made to the wrong region. The Go SDK does require that the request are made to the correct region. The redirect provided by S3 is not intended to actually be followed in this case. That is why the Location header is not set. If your application has access to the bucket you could do S3.GetBucketLocaltion() to get the bucket's region. Or if not not performing a HEAD request on the bucket to receive the Bucket's location in the curl -I "https://bucketname.s3.amazonaws.com" Or in Go, This functionality isn't currently in the SDK but can be implemented simply with the below. resp, err := http.Head("https://bucketname.s3.amazonaws.com")
if err != nil {
fmt.Println("ERROR", err)
return
}
fmt.Println("Region:", resp.Header.Get("X-Amz-Bucket-Region")) |
I pushed 9411a1e which fixes the multiple retries when the request should of not retried at all. Thanks for reporting this issue, if you have an more issues or feedback please let us know. |
@jasdel thanks for the explanation and fix. I'll update my docs to indicate the above. PS http://rclone.org is now using the new SDK - the managed multipart upload was a real timesaver thanks! |
Great let us know if you run into any issues with the SDK, new features/tools we can add, or things we can do better. |
…ws#356) Fixes the EC2 Instance Metadata Service client to no longer squash the trailing slash when requesting instance metadata. Also, fixes the iamSecurityCredsPath var to include a trailing slash preventing redirects when making requests to the EC2 Instance Metadata service. Fix aws#351 Related to aws#351
Services === * Synced the V2 SDK with latest AWS service API definitions. * Fixes [aws#359](aws/aws-sdk-go-v2#359) SDK Features === SDK Enhancements === * `private/protocol`: Add support for TimestampFormat in protocols ([aws#358](aws/aws-sdk-go-v2#358)) * Adds support for the timestampForamt API model trait to the V2 SDK. The SDK will now generate API client parameters with the correct time format for APIs modeled with custom time stamp formats specified. * Fixes [aws#202](aws/aws-sdk-go-v2#202) * Fixes [aws#286](aws/aws-sdk-go-v2#286) * `aws`: Add example for custom HTTP client idle connection options ([aws#350](aws/aws-sdk-go-v2#350)) * Adds example to the SDK for configuring custom HTTP client idle connection keep alive options. SDK Bugs === * `private/model/api`: Fix API doc being generated with wrong value ([aws#359](aws/aws-sdk-go-v2#359)) * Fixes the SDK's generated API documentation for structure member being generated with the wrong documentation value when the member was included multiple times in the model doc-2.json file, but under different types. * V2 port of to v1 [aws#2748](aws#2748) * `aws/ec2rolecreds`: Fix security creds path to include trailing slash ([aws#356](aws/aws-sdk-go-v2#356)) * Fixes the iamSecurityCredsPath var to include a trailing slash preventing redirects when making requests to the EC2 Instance Metadata service. * Fixes [aws#351](aws/aws-sdk-go-v2#351) * `service/dynamodb/expression`: Improved reporting of bad key conditions ([aws#360](aws/aws-sdk-go-v2#360)) * Improved error reporting when invalid key conditions are constructed using KeyConditionBuilder
Thanks @jasdel for pointing me in the right direction. I spent a few days wondering why the Instead of using |
Though it may be far too late to revisit this, maybe this error should actually be retried by the AWS SDKs for consistency? The AWS CLI does seem to retry this error, and the information is actually provided in the headers (or body) to complete the redirect - no need for an additional call. For example...
Results in this response (formatted):
botocore itself handles this with a "redirect from error handler": S3RegionRedirectorv2, which is enabled by default. and not easily configurable. As an aside, even if it is too late to make this the default behavior for the go library for backwards compatibility reasons, it seems like it would be a nice configurable affordance for end-user libraries. I was pointed here through issues in |
If I create a bucket in one region, then try to access it from a different region s3 sends a redirect, however the library doesn't recognize it. Here is what I get from the debug
Here I created a bucket in the default region and am now trying to list it from us-west-1
This then repeats to make 10 times before returning an error
What I think is happening is that s3 sends a redirect but the library doesn't deal with it correctly, and retries instead.
The text was updated successfully, but these errors were encountered: