When users try to access objects in my Amazon Simple Storage Service (Amazon S3) bucket they receive a 404 NoSuchKey error.
Resolution
Amazon S3 might return 404 errors if the requested object is missing from the bucket. Before users make GET or HEAD requests for an object, check that the object is created and available in the S3 bucket.
To check if an object is available in a bucket, review the contents of the bucket from the Amazon S3 console. Or, you can use AWS Command Line Interface (AWS CLI) to run the head-object command:
aws s3api head-object --bucket awsexamplebucket --key object.jpg
Note: If you receive errors when you run AWS CLI commands, then see Troubleshoot AWS CLI errors. Also, make sure that you're using the most recent AWS CLI version.
Amazon S3 delivers strong read-after-write consistency for all applications. After a successful write of a new object, or an overwrite or delete of an existing object, any subsequent read request immediately receives the latest version of the object. Amazon S3 also provides strong consistency for list operations. After a write, you can perform a listing of the objects in a bucket. For more information about Amazon S3 consistency, see Amazon S3 Strong Consistency.
If the requested object is available in the S3 bucket and you receive a 404 NoSuchKey error again, then check the following:
- Confirm that the request matches the object name exactly. Requests for S3 objects are case sensitive. For example, if an object is named myimage.jpg, but Myimage.jpg is requested, then the requester receives a 404 NoSuchKey error.
- Confirm that the requested path matches the path to the object. Otherwise, the requester receives a 404 NoSuchKey error.
- If the path to the object contains any spaces, then check that the request uses the correct syntax to recognize the path. For example, if you use AWS CLI to download an object to your Windows machine, then you must use quotation marks around the object path. The object path must look 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 are 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, run the list-objects-v2 command with the parameter --output json. The JSON output makes characters such as returns (\r) visible. If an object name has a special character that's not always visible, then remove the character from the object name. Try to access the object again.
- (Optional) You can turn on server access logging to review request records in further detail for issues that might cause a 404 NoSuchKey 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. If you receive a 403 Access Denied error, then resolve the issue related to the missing object.
Related information
Troubleshoot Access Denied (403 Forbidden) errors in Amazon S3