|
1 | | -// Runs inside the video image, mounted into /var/task: the bundled ffmpeg answers and the arm64 Chrome |
2 | | -// renders a page, launched the way src/chromium.ts launches it. |
| 1 | +// A handler mounted into the video image and invoked through its own Lambda bootstrap, which sets |
| 2 | +// AWS_EXECUTION_ENV as Lambda does: the bundled ffmpeg answers and arm64 Chrome renders, launched as |
| 3 | +// src/chromium.ts launches it. |
3 | 4 | import { execFileSync } from "node:child_process"; |
4 | 5 | import chromium from "@sparticuz/chromium"; |
5 | 6 | import puppeteer from "puppeteer-core"; |
6 | 7 |
|
7 | | -const ffmpeg = execFileSync("/var/task/bin/ffmpeg", ["-hide_banner", "-version"], { |
8 | | - encoding: "utf-8", |
9 | | -}); |
10 | | -console.log(ffmpeg.split("\n")[0]); |
11 | | -const browser = await puppeteer.launch({ |
12 | | - executablePath: await chromium.executablePath(), |
13 | | - args: chromium.args, |
14 | | -}); |
15 | | -try { |
16 | | - const page = await browser.newPage(); |
17 | | - await page.setContent("<div style='width:64px;height:64px;background:#0a0'></div>"); |
18 | | - const shot = await page.screenshot({ clip: { x: 0, y: 0, width: 64, height: 64 } }); |
19 | | - console.log(`${await browser.version()} on ${process.arch}: ${shot.length} byte screenshot`); |
20 | | -} finally { |
21 | | - await browser.close(); |
22 | | -} |
| 8 | +export const handler = async () => { |
| 9 | + const ffmpeg = execFileSync("/var/task/bin/ffmpeg", ["-hide_banner", "-version"], { |
| 10 | + encoding: "utf-8", |
| 11 | + }).split("\n")[0]; |
| 12 | + const browser = await puppeteer.launch({ |
| 13 | + executablePath: await chromium.executablePath(), |
| 14 | + args: chromium.args, |
| 15 | + }); |
| 16 | + try { |
| 17 | + const page = await browser.newPage(); |
| 18 | + await page.setContent("<div style='width:64px;height:64px;background:#0a0'></div>"); |
| 19 | + const shot = await page.screenshot({ clip: { x: 0, y: 0, width: 64, height: 64 } }); |
| 20 | + return { |
| 21 | + executionEnv: process.env.AWS_EXECUTION_ENV, |
| 22 | + arch: process.arch, |
| 23 | + ffmpeg, |
| 24 | + chrome: await browser.version(), |
| 25 | + screenshotBytes: shot.length, |
| 26 | + }; |
| 27 | + } finally { |
| 28 | + await browser.close(); |
| 29 | + } |
| 30 | +}; |
0 commit comments