Request Redirection and the REST API
Overview
Amazon S3 uses the Domain Name System (DNS) to route requests to facilities that can process them. This system works very effectively. However, temporary routing errors can occur.
If a request arrives at the wrong Amazon S3 location, Amazon S3 responds with a temporary redirect that tells the requester to resend the request to a new endpoint.
If a request is incorrectly formed, Amazon S3 uses permanent redirects to provide direction on how to perform the request correctly.
Important | |
---|---|
Every Amazon S3 program must be designed to handle redirect responses. The only
exception is for programs that work exclusively with buckets that were created
without |
DNS Routing
DNS routing routes requests to appropriate Amazon S3 facilities.
The following figure shows an example of DNS routing.
1 | The client makes a DNS request to get an object stored on Amazon S3. |
2 | The client receives one or more IP addresses for facilities that can process the request. |
3 | The client makes a request to Amazon S3 Facility B. |
4 | Facility B returns a copy of the object. |
Temporary Request Redirection
A temporary redirect is a type of error response that signals to the requester that he should resend his request to a different endpoint.
Due to the distributed nature of Amazon S3, requests can be temporarily routed to the wrong facility. This is most likely to occur immediately after buckets are created or deleted. For example, if you create a new bucket and immediately make a request to the bucket, you will receive a temporary redirect. After information about the bucket propagates through DNS, redirects will be rare.
Temporary redirects contain a URI to the correct facility which you can use to immediately resend the request.
Important | |
---|---|
Do not reuse an endpoint provided by a previous redirect response. It might appear to work (even for long periods of time), but might provide unpredictable results and will eventually fail without notice. |
The following figure shows an example of a temporary redirect.
1 | The client makes a DNS request to get an object stored on Amazon S3. |
2 | The client receives one or more IP addresses for facilities that can process the request. |
3 | The client makes a request to Amazon S3 Facility B. |
4 | Facility B returns a redirect indicating the object is available from Location C. |
5 | The client resends the request to Facility C. |
6 | Facility C returns a copy of the object. |
Permanent Request Redirection
A permanent redirect indicates that your request addressed a resource inappropriately.
For example, permanent redirects occur if you use a path-style request to access a
bucket that was created using <CreateBucketConfiguration>
. For more
information, see Using
CreateBucketConfiguration.
To help you find these errors during development, this type of redirect does not contain a Location HTTP header that allows you to automatically follow the request to the correct location. Consult the resulting XML error document for help using the correct Amazon S3 endpoint.
Example REST API Redirect
HTTP/1.1 307 Temporary Redirect Location: http://johnsmith.s3-gztb4pa9sq.amazonaws.com/photos/puppy.jpg?rk=e2c69a31 Content-Type: application/xml Transfer-Encoding: chunked Date: Fri, 12 Oct 2007 01:12:56 GMT Server: AmazonS3 <?xml version="1.0" encoding="UTF-8"?> <Error> <Code>TemporaryRedirect</Code> <Message>Please re-send this request to the specified temporary endpoint. Continue to use the original request endpoint for future requests.</Message> <Endpoint>johnsmith.s3-gztb4pa9sq.amazonaws.com</Endpoint> </Error>
Example SOAP API Redirect
<soapenv:Body> <soapenv:Fault> <Faultcode>soapenv:Client.TemporaryRedirect</Faultcode> <Faultstring>Please re-send this request to the specified temporary endpoint. Continue to use the original request endpoint for future requests.</Faultstring> <Detail> <Bucket>images</Bucket> <Endpoint>s3-gztb4pa9sq.amazonaws.com</Endpoint> </Detail> </soapenv:Fault> </soapenv:Body>