_downloadManifest()

in source/custom-resource/lib/s3-helper.js [209:251]


    _downloadManifest(s3Bucket, s3Key) {
        let _self = this;
        return new Promise((resolve, reject) => {

            let params = {
                Bucket: s3Bucket,
                Key: s3Key
            };

            console.log(`Attempting to download manifest: ${JSON.stringify(params)}`);

            // check to see if the manifest file exists
            let s3 = new AWS.S3({
                signatureVersion: 'v4'
            });
            s3.headObject(params, function(err, metadata) {
                if (err) {
                    console.log(err);
                }

                if (err && err.code === 'NotFound') {
                    // Handle no object on cloud here
                    console.log('manifest file doesn\'t exist');
                    reject('Manifest file was not found.');
                } else {
                    console.log('manifest file exists');
                    console.log(metadata);
                    let file = require('fs').createWriteStream(_self.downloadLocation);

                    s3.getObject(params).
                    on('httpData', function(chunk) {
                        file.write(chunk);
                    }).
                    on('httpDone', function() {
                        file.end();
                        console.log('manifest downloaded for processing...');
                        resolve('success');
                    }).
                    send();
                }
            });
        });
    }