441642 (2) [Avatar] Offline
#1
I was trying to complete exercise 3.2 item 2 - delete invalid files off a S3 bucket. I cannot figure out why the code below does not work. the role has the correct inline policy (plus i have opened it right up for s3 admin rights to test). I have checked the cloudwatch logs and the function reports that the file has been deleted as below in the js code

but no matter what i do i cannot delete a file off the s3 bucket.

I am fairly sure the below code and permissions are correct - so was wondering if anyone has had a similar problem - or am I missing something. This is a great book and really like the challenge exercises.

-----
IAM policy found on the net
-----


{
"Statement": [
{
"Sid": "Stmt1423535846414",
"Action": [
"s3smilieeleteObject"
],
"Effect": "Allow",
"Resource": "arn:aws:s3:::mybucket-name/*"
}
]
}


------

javascript

-------

var s3 = new AWS.S3();

function deleteS3object(ObjName) { // Delete files of invalid extensions , but currently not working???
var objectName = ObjName;
console.log("s3 Object Name:" + ObjName);

var params = {
Bucket: 'mybucket-name' ,
Key: '/' + objectName
};
s3.deleteObject(params, function (err, data) {
if (data) {
console.log("File deleted");
}
else {
console.log("Error file NOT deleted: "+err);
}
});
}
Peter Sbarski (17) [Avatar] Offline
#2
Thank you for your feedback regarding our book! I really appreciate it.

You might be supplying the wrong key to s3.deleteObject(). This API call will look like it succeeded if you supply a key of a file that doesn't exist (however, it will show an error if you specify a bucket that doesn't exist).