Skip to content
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

Closed
earleoxner opened this issue Oct 19, 2020 · 24 comments
Closed

Using in AWS Lambda Function #70

earleoxner opened this issue Oct 19, 2020 · 24 comments

Comments

@earleoxner
Copy link

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.

@frinyvonnick
Copy link
Owner

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 👍

@earleoxner
Copy link
Author

earleoxner commented Oct 19, 2020 via email

@frinyvonnick
Copy link
Owner

frinyvonnick commented Oct 20, 2020

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 😄

@earleoxner
Copy link
Author

earleoxner commented Oct 20, 2020 via email

@frinyvonnick
Copy link
Owner

frinyvonnick commented Oct 21, 2020

If you find a solution @earleoxner could you share it here so it can help somebody else?

@Ramakant701
Copy link

how one can change pupeeteer used internally?

@frinyvonnick
Copy link
Owner

Hi @Ramakant701 👋

I don't understand your question. Can you reformulate it? What do you expect?

@earleoxner
Copy link
Author

earleoxner commented Oct 21, 2020 via email

@Ramakant701
Copy link

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

@Ramakant701
Copy link

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

@earleoxner
Copy link
Author

earleoxner commented Oct 21, 2020 via email

@earleoxner
Copy link
Author

earleoxner commented Oct 21, 2020 via email

@frinyvonnick
Copy link
Owner

frinyvonnick commented Oct 21, 2020

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 👌

Repository owner deleted a comment from earleoxner Oct 21, 2020
Repository owner deleted a comment from earleoxner Oct 21, 2020
@frinyvonnick
Copy link
Owner

I deleted duplicated comments from @earleoxner to avoid confusion.

@Ramakant701
Copy link

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 👌

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

@frinyvonnick
Copy link
Owner

puppeteer-serverless only works with AWS Lambda sadly @Ramakant701 😢

@Ramakant701
Copy link

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?

@Ramakant701
Copy link

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

@Ramakant701
Copy link

I have found one solution but this will require you to update pupeeteer version 3 to latest @frinyvonnick. can you please do that?

@Ramakant701
Copy link

"Error: Unable to get browser page",
" at Worker. (/var/task/node_modules/node-html-to-image/node_modules/puppeteer-cluster/dist/Worker.js:44:31)"

@frinyvonnick
Copy link
Owner

frinyvonnick commented Oct 24, 2020

@Ramakant701 would you be interested in opening a pull request that updates pupeteer to last version?

@earleoxner
Copy link
Author

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.

@collindutter
Copy link

To anyone coming to this thread late, this article got me exactly what I needed:
https://www.mayvisblog.com/aws-lambda-serverless-function-to-generate-image-from-html/

@frinyvonnick
Copy link
Owner

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants