-
-
Notifications
You must be signed in to change notification settings - Fork 125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using in AWS Lambda Function #70
Comments
Hi @earleoxner 👋 Thank you for posting this issue. node-html-to-image uses puppeteer under the hood. You can find more information about how to use puppeteer on AWS Lambda in its troubleshooting section. Please close this issue if it solves your issue 👍 |
Thanks! I installed the chrome-aws-lambda like it said. I don’t see how your code connects to it and the error I am getting is that it is unable to launch browser and says that I should install one. To try to get the size down, I installed serverless-webpack. Once I did that, it stopped trying to deploy the chromium and puppeteer that you are using. I am not sure how to glue your code and the chrome-was-lambda together. They do have sample code to start a browser and I can do that but I was not sure if there were certain things your code is relying on. Any thoughts on that? That code they menioned to use for the chrome-was-lambda package is below:
const chromium = require('chrome-aws-lambda');
exports.handler = async (event, context, callback) => {
let result = null;
let browser = null;
try {
browser = await chromium.puppeteer.launch({
args: chromium.args,
defaultViewport: chromium.defaultViewport,
executablePath: await chromium.executablePath,
headless: chromium.headless,
ignoreHTTPSErrors: true,
});
let page = await browser.newPage();
await page.goto(event.url || 'https://example.com');
result = await page.title();
} catch (error) {
return callback(error);
} finally {
if (browser !== null) {
await browser.close();
}
}
return callback(null, result);
};
Earle
Earle Oxner
[email protected]
… On Oct 19, 2020, at 1:55 PM, Yvonnick FRIN ***@***.***> wrote:
Hi @earleoxner <https://github.com/earleoxner> 👋
Thank you for posting this issue. node-html-to-image uses puppeteer under the hood. You can find more information about how to use puppeteer on AWS Lambda in its troubleshooting <https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#running-puppeteer-on-aws-lambda> section.
Please close this issue if it solves your issue 👍
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#70 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AL545IOUYRHQXJKEHXRS2GLSLR4S7ANCNFSM4SWJFC5Q>.
|
node-html-to-image also uses puppeteer-cluster to batch image creation maybe you can find more information about your problem on its repository. Sorry I don't know much about AWS Lambda. I'm currently in holidays I don't have time to search more about it. Hope you will find something helpful 😄 |
Thank you.
…Sent from my mobile device
On Oct 20, 2020, at 3:25 AM, Yvonnick FRIN ***@***.***> wrote:
node-html-to-image also uses puppeteer-cluster to batch image creation maybe you can find more information about your problem on its repository. Sorry I don't know much about AWS Lambda. I'm currently in holidays I don't have time to search more about it.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
If you find a solution @earleoxner could you share it here so it can help somebody else? |
how one can change pupeeteer used internally? |
Hi @Ramakant701 👋 I don't understand your question. Can you reformulate it? What do you expect? |
Will do. Still working on it.
…Sent from my mobile device
On Oct 21, 2020, at 2:51 AM, Yvonnick FRIN ***@***.***> wrote:
If you find a solution @earleoxner could you share it here so it can help somebody else?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
Please let me know as well, I'm also trying to figure out any Solution to it |
I'm figuring out a way to change puppeteer node html to image is using internally, seems like we can fix it by providing an option to be sent to nodeHtmlToImage like useServerless which is when set to true will make use of pupeeteer serverless as package to launch chromium instead of pupeeteer |
Yesterday, I took my code and replaced node-html-to-image with chromium-aws-lambda and I got a buffer back but it wouldn’t display in my app. I then replaced the chromium-aws-lambda with puppeteer and it worked fine. I changed the puppeteer launch call a little but that was it. I noticed the buffers returned were similar but a little different in both size and content. It looks like maybe it is a different file format or encoding. I have an email into the developer of chromium-aws-lambda. I don’t get any errors. FYI.
…Sent from my mobile device
On Oct 21, 2020, at 7:39 AM, Ramakant Singh ***@***.***> wrote:
Hi @Ramakant701 👋
I don't understand your question. Can you reformulate it? What do you expect?
I'm figuring out a way to change puppeteer node html to image is using internally, seems like we can fix it by providing an option to be sent to nodeHtmlToImage like useServerless which is when set to true will make use of pupeeteer serverless as package to launch chromium instead of pupeeteer
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
And I should add that when I used chromium-was-lambda I was running the nodejs code in a lambda function at AWS. Puppeteer was done using serverless offline (I.e. local)
…Sent from my mobile device
On Oct 21, 2020, at 7:39 AM, Ramakant Singh ***@***.***> wrote:
Hi @Ramakant701 👋
I don't understand your question. Can you reformulate it? What do you expect?
I'm figuring out a way to change puppeteer node html to image is using internally, seems like we can fix it by providing an option to be sent to nodeHtmlToImage like useServerless which is when set to true will make use of pupeeteer serverless as package to launch chromium instead of pupeeteer
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
It sounds like a good idea @Ramakant701! But it should work for most of the cloud provider not AWS only 🤔 Thank you @earleoxner for investigating it 👌 |
I deleted duplicated comments from @earleoxner to avoid confusion. |
makes sense and thus I propose to use https://www.npmjs.com/package/puppeteer-serverless - this will take care of all - let me know if we can implement this ASAP |
puppeteer-serverless only works with AWS Lambda sadly @Ramakant701 😢 |
so can we have an option for lambda for now and later release it for other serverless like gcloud and others? |
At the same time how about replacing the puppeteer altogether? like in nodeHtmlToImage option send the puppeteer user wants to use instead of default? but this will require more changes I feel |
I have found one solution but this will require you to update pupeeteer version 3 to latest @frinyvonnick. can you please do that? |
"Error: Unable to get browser page", |
@Ramakant701 would you be interested in opening a pull request that updates pupeteer to last version? |
I ended up using the chromium_aws_lambda library and there is an exclude statement you have to place in the package area of your serverless.yml in order to not include chromium when deploying to AWS. Once I did that, it got up there correctly. I did include the latest puppeteer, puppeteer-core and @types/puppeteer. You then call the puppeteer functions directly and there are examples of how to do that in the chromium_aws_lambda site. I used sharp in order to resize the image down to a thumbnail size and in order for that to work, you have to use the linux version and there are installation instructions on how to do that on the sharp website. |
To anyone coming to this thread late, this article got me exactly what I needed: |
Hey @collindutter, thank you for sharing! This is really interesting because the instance made with chrome-aws-lambda could be passed down to node-html-to-image 🤔 I'm discussing the possibility to add a puppeteer instance property here #80 (comment) |
I have enjoyed using the library so far. The one issue I have is that I can't deploy to a AWS Lambda function because the library (including Chromium I guess) pushes the size of the deployment package greater than 250MB. Any thoughts on how to make this deploy to AWS Lambda? I can use in a lambda function offline but can't be deployed due to package size.
The text was updated successfully, but these errors were encountered: