S3 bucket events

Hello all,

I am a total nodejs newbie and I am trying to create a serverless plugin to create events on a S3 bucket (and subfolders) to trigger a Lambda.

I figured out how to create a single event, but when creating multiple events (by adding more items to MyFoldersArray) I run into the following error message ("‘A conflicting conditional operation is currently in progress against this resource. Please try again.’") and I can’t figure out how to resolve this issue. Maybe you have some ideas to point me in the right direction.

My code;

‘use strict’;

// Load the SDK for JavaScript
const AWS = require(‘aws-sdk’);

// Set the region
AWS.config.update({region: ‘ap-southeast-2’});

// Create S3 service object
var s3 = new AWS.S3({apiVersion: ‘2006-03-01’});

var MyFoldersArray = [‘mytestfolder/1’, ‘mytestfolder2/’]; // fails with the “A conflicting conditional operation is currently in progress against this resource. Please try again.” error message
//var MyFoldersArray = [‘mytestfolder/’] // works!

const runTask = async function() {
for(var folder of MyFoldersArray) {
try {
var bucket_params = {
Bucket: “mytestbucket”,
NotificationConfiguration: { /* required /
LambdaFunctionConfigurations: [
{
Events: [ /
required /
"s3:ObjectCreated:
",
/* more items */
],
LambdaFunctionArn: “arn:aws:lambda:ap-southeast-2:myaccountid:function:hello_world”,
Filter: {
Key: {
FilterRules: [
{
Name: “prefix”,
Value: folder
},
]
}
},
Id: folder
},
]
}
};
let result = await s3.putBucketNotificationConfiguration(bucket_params, function(err, data) {
console.log("error is: ", err);
console.log("data is: ", data);
}).promise();
console.log("result is: ", result);
} catch (err) {
console.log(err);
}
}
}

runTask()

Managed to fix the issue, will be creating a plugin for it.