How do I resolve the ERROR: S3 error: 404 (NoSuchKey) when using s3cmd?
I'm getting the following error when trying to set my bucket policy with s3cmd setpolicy bucket-policy-test.json s3://mybucket
ERROR: S3 error: 404 (NoSuchKey)
How can I resolve this? Here is the json file I'm using:
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Deny",
"Principal": "*",
"Action": "s3:*",
"Resource": "arn:aws:s3:::bucket-policy-example/*",
"Condition": {
"NotIpAddress": {
"aws:SourceIp": "172.104.2.4"
}
}
}]
}
1 Reply
I tested this out by on one of my existing buckets as well as a new bucket, with the same json
file (though I formatted mine as a txt
file.)
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Deny",
"Principal": "*",
"Action": "s3:*",
"Resource": "arn:aws:s3:::bucket-policy-example/*",
"Condition": {
"NotIpAddress": {
"aws:SourceIp": "172.104.2.4"
}
}
}]
}
When I ran:
s3cmd setpolicy bucket-policy-test.txt s3://mybucket
In both cases I did not run into the error, and the bucket policy was applied. For example:
s3cmd setpolicy bucket-policy-test.txt s3://mybucket
~ % s3cmd info s3://mybucket
s3://mybucket/ (bucket):
Location: default
Payer: BucketOwner
Expiration Rule: none
Policy: b'{\n "Version": "2012-10-17",\n "Statement": [{\n "Effect": "Deny",\n "Principal": "*",\n "Action": "s3:*",\n "Resource": "arn:aws:s3:::bucket-policy-example/*",\n "Condition": {\n "NotIpAddress": {\n "aws:SourceIp": "172.104.2.4"\n }\n }\n }]\n}\n'
The first thing to check might be whether your json is valid using a json validator.
Aside from that, in doing some research on this, the most helpful resource I came across was this:
https://aws.amazon.com/premiumsupport/knowledge-center/404-error-nosuchkey-s3/
Based on this, it could have something to do with the syntax of the command, the file path or special characters used.