Why does puppeteer timeout from lambda when calling a cloud front url?

30 Views Asked by At

So i have a simple lambda function that calls a URL.

I want it to then return the contents of the URL.

The URL I cam calling is tied to a cloud front instance (which inturn turn sets a few headers via lambda edge functions);

The function works locally and returns the HTML as expected.

But as soon as I upload it, it times out when calling the page.

Here is the lambda function (uses a layer with puppeteer installed, confirmed to be working also)

import chromium from '@sparticuz/chromium';
import puppeteer from "puppeteer-core";

export async function handler(event) {
    let browser = null;

    const launchConfig = {
        args: [...chromium.args, '--start-maximized'],
        defaultViewport: chromium.defaultViewport,
        executablePath: await chromium.executablePath(),
        headless: chromium.headless,
        // headless: false,
        ignoreDefaultArgs: ['--disable-extensions']
    }

    console.log(launchConfig);


    browser = await puppeteer.launch(launchConfig);

    console.log('create the new page');
    const page = await browser.newPage();

    console.log('set the timeout');
    page.setDefaultNavigationTimeout(0);

    console.log('navigate to', event.url);
    // Navigate to the Vue.js app URL
    await page.goto(event.url);
    console.log('after page');

    // Extract the updated HTML
    const html = await page.evaluate(() => {
        return document.documentElement.outerHTML;
    });

    await browser.close();

    return {
        statusCode: 200,
        body: html,
    }
}

I have a lambda test setup which sends

{
  "url": "https://theurl.com"
}

when the url is of another site, not using cloud front it reaches the end.

But when I call a site managed via cloud front (on the same account) it doesn't make it past here await page.goto(event.url);.

Further to this, I enabled cloud front aws-waf logs, and I can see the request coming in and it looks to be accepted.

So I am at a loss of where to go from here

0

There are 0 best solutions below