stiekel/aliexpress

Time out on AWS Lambda

AlexzanderFlores opened this issue · 0 comments

Hello, I am attempting to use this package on an AWS Lambda function, however it keeps timing out without any explanation as to why. I have made some small edits to the package for my own personal taste, but none of these changes stop it from working on my local Windows environment or on a Centos environment on a VPS.

This is my current code:

const aliexpress = require('aliexpress');

exports.handler = (event, context, callback) => {
	aliexpress.scrape('http://bestselling.aliexpress.com/en?spm=2114.11010108.21.4.dkHNPl', (err, $) => {
		if(err) {
			callback(err);
		} else {
			const goods = [];
			$('#bestselling-top10 .item-desc').each((key, lk) => {
				if(lk && lk.attribs && lk.attribs.href) {
					if(!goods[key]) {
						goods[key] = {}
					}
					goods[key].url = lk.attribs.href;
					if(lk.children && lk.children[0] && lk.children[0].data) {
						goods[key].name = lk.children[0].data;
					}
				}
			});
			$('#bestselling-top10 .item-price .price').map((key, lk) => {
				if(lk) {
					if(lk.children && lk.children[0] && lk.children[0].data) {
						goods[key].price = lk.children[0].data;
					}
				}
			});
			const urls = [];
			for(let index in goods) {
				let url = 'https://' + goods[index].url.substring(2).split('?')[0];
				urls.push(url);
			}
			callback(null, urls);
		}
	});
}

// For testing on my Centos environment

/*exports.handler(null, null, (err, result) => {
	if(err) {
		return console.log(err);
	}
	console.log(result);
});*/

Again, this works perfectly on my local Windows environment AND a Centos 7 environment on a VPS. Note that my lambda function does have the phantomjs linux executable and NOT the .exe.

On my lambda function I get this:

{
  "errorMessage": "2017-12-03T15:58:01.171Z b6c11df8-d842-11e7-97c8-0bbe0f0854b3 Task timed out after 10.00 seconds"
}

The max time is set for 10 seconds, but this happens with 20 seconds, etc. Not sure if this is related to this library specifically, or if it is a phantomjs exclusive problem. This is my first time working with either so I decided to report this here first.