forked from anomalyco/sst
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlambda.js
More file actions
32 lines (25 loc) · 796 Bytes
/
Copy pathlambda.js
File metadata and controls
32 lines (25 loc) · 796 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import chrome from "chrome-aws-lambda";
// chrome-aws-lambda handles loading locally vs from the Layer
const puppeteer = chrome.puppeteer;
export async function handler(event) {
// Get the url and dimensions from the query string
const { url, width, height } = event.queryStringParameters;
const browser = await puppeteer.launch({
args: chrome.args,
executablePath: await chrome.executablePath,
});
const page = await browser.newPage();
await page.setViewport({
width: Number(width),
height: Number(height),
});
// Navigate to the url
await page.goto(url);
return {
statusCode: 200,
// Return as binary data
isBase64Encoded: true,
headers: { "Content-Type": "image/png" },
body: await page.screenshot({ encoding: "base64" }),
};
}