How can I troubleshoot the 404 "NoSuchKey" error from Amazon S3?
Last updated: 2019-12-17
My users are trying to access objects in my Amazon Simple Storage Service (Amazon S3) bucket. However, Amazon S3 is returning the 404 "NoSuchKey" error. How can I troubleshoot this error?
Amazon S3 generally returns 404 errors if the requested object is missing from the bucket. Before users make GET or HEAD requests for an object, be sure that the object is created and is available in the bucket. To check if an object is available in a bucket, you can review the contents of the bucket from the Amazon S3 console. Or, you can run the head-object command using the AWS Command Line Interface (AWS CLI):
aws s3api head-object --bucket awsexamplebucket --key object.jpg
Additionally, Amazon S3 might return the "NoSuchKey" error if the object was recently uploaded. When you upload an object, Amazon S3 replicates your data across multiple servers, so the newly uploaded object might not be found until after the object is completely replicated across the multiple servers. Amazon S3 provides eventual consistency for read-after-write if a GET or HEAD object call is made before the object upload. To avoid the "NoSuchKey" error for a newly uploaded object, wait a few seconds after the PUT request, and then you can make the first attempt to access the object.
If the requested object was available in the bucket for some time and users are still getting the 404 NoSuchKey error from Amazon S3, then check the following:
- Confirm that the request matches the object name exactly, including the capitalization of the object name. Requests for S3 objects are case sensitive. For example, if an object is named myimage.jpg, but Myimage.jpg is requested, then requester receives a 404 NoSuchKey error.
- Confirm that the requested path matches the path to the object. For example, if the path to an object is awsexamplebucket/Downloads/February/Images/image.jpg, but the requested path is awsexamplebucket/Downloads/February/image.jpg, then the requester receives a 404 NoSuchKey error.
- If the path to the object contains any spaces, be sure that the request uses the correct syntax to recognize the path. For example, if you're using the AWS CLI to download an object to your Windows machine, you must use quotation marks around the object path, similar to: aws s3 cp "s3://awsexamplebucket/Backup Copy Job 4/3T000000.vbk".
- Check the object name for any special characters or URL-encoded characters that might be difficult to see such as carriage returns (\r) or new lines (\n). For example, the object name test with a carriage return at the end shows as test%0A in the Amazon S3 console. To check object names for special characters, you can run the list-objects-v2 command with the parameter --output json. The JSON output makes characters like returns (\r) visible. If an object name has a special character that's not always visible, remove the character from the object name, and then try accessing the object again.
- Optionally, you can enable server access logging to review request records in further detail for issues that might be causing the 404 error.
Note: If an object is missing from the bucket and the requester doesn’t have s3:ListBucket access, then the requester receives a 403 Access Denied error instead of a 404 error. If this is the case, you must resolve the issue related to the missing object to resolve the 403 Access Denied error.