The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

441642 (2) [Avatar] Offline
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": [
"Effect": "Allow",
"Resource": "arn:aws:s3:::mybucket-name/*"




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 (18) [Avatar] Offline
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).