0

I'm getting this error:

"lambdaCallbackWith": [
      "TypeError: #<Promise> is not a function",
      "at Array.forEach (<anonymous>)",

When i ran the code below:

   var resizeVolume =  function* (event, context) {          

        var co = require('co');
        volumes.forEach(co(function *(volume) {

         yield eC2.setNewVolume(volume.VolumeId, volumeSize);                        
        })); 
    }

The error occurred in foreach, i added the CO but no success.

The code without CO show an error saying the yield is a reserved word.

1 Answers1

0

yield can only be used in a generator function. That's why

volumes.forEach(() => {
    yield ...
})

Won't work.

You will need a library to use a generator in a forEach loop such as co-foreach.

If you don't want to you can use a regular for loop like this:

const co = require('co');

var resizeVolume =  function* (event, context) {          
    co.wrap(function *() {
        for (let i = 0 ; i < volumes.lenght ; i++) {
            const volume = volumes[i];
            yield eC2.setNewVolume(volume.VolumeId, volumeSize);
        }                       
    }); 
}
Baboo
  • 4,008
  • 3
  • 18
  • 33