I'm trying to do something similar to what this person did but I'm having difficulty figuring out how to redirect the output of Puppeteer screenshotting directly to S3 as the screenshot function only has a parameter for local directory paths. Storing the images on Lambda is an option but not a preferred one.
Passing a path to screenshot
is optional. You can omit the path and use the Promise<[Buffer|String]>>
it returns as the content for a new S3 object (after await
ing it). Assuming you have the AWS SDK and a bucket set up already, your configuration will look something like this:
const AWS = require("aws-sdk");
const s3 = new AWS.S3();
const bucket = "your.bucket.name";
const key = "yourObjectKey";
Then, wherever you’re ready to take the screenshot:
const screenshot = await page.screenshot();
const params = { Bucket: bucket, Key: key, Body: screenshot };
await s3.putObject(params).promise();
Depending on what you intend to use it for, you may want to add ContentType
or other relevant headers to the parameters. You can see the list in the documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With