I am trying to run puppeteer with proxy chain package on aws lambda but I am getting this error message:
"errorType": "Error", "errorMessage": "Protocol error (Target.createTarget): Target closed."
const chromium = require('chrome-aws-lambda'); | |
const { addExtra } = require("puppeteer-extra"); | |
const puppeteerExtra = addExtra(chromium.puppeteer); | |
const proxyChain = require('proxy-chain'); | |
const StealthPlugin = require("puppeteer-extra-plugin-stealth"); | |
puppeteerExtra.use(StealthPlugin()); | |
exports.handler = async (event, context, callback) => { | |
let finalResult = []; | |
const url = ``; | |
let browser; | |
const oldProxyUrl = ''; // --> bright data proxy | |
const newProxyUrl = await proxyChain.anonymizeProxy(oldProxyUrl); | |
console.log("newProxyUrl", newProxyUrl) | |
try { | |
browser = await puppeteerExtra.launch({ | |
args: ['--no-sandbox', '--disable-setuid-sandbox', `--proxy-server=${newProxyUrl}`], | |
defaultViewport: chromium.defaultViewport, | |
executablePath: await chromium.executablePath, | |
headless: chromium.headless | |
}); | |
const page = await browser.newPage(); | |
await page.goto(url); | |
finalResult = await extractElements(page); | |
} catch (error) { | |
return callback(error); | |
} finally { | |
await browser.close(); | |
await proxyChain.closeAnonymizedProxy(newProxyUrl, true); | |
} | |
return callback(null, finalResult); | |
}; |
Sorry did not get you. Are you saying I have to enable proxy settings for lambda function?
@aditodkar Did you test well at local? If yes, maybe AWS lambda block proxy. let's try to config allow proxy on lambda