Merge pull request #54 from Sparticuz/feature/examples

This commit is contained in:
Kyle McNally 2023-02-09 11:26:27 -05:00 committed by GitHub
commit 58460d821c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 120 additions and 1 deletions

2
.github/FUNDING.yml vendored
View File

@ -1 +1 @@
github:Sparticuz
github: Sparticuz

2
.gitignore vendored
View File

@ -10,3 +10,5 @@ _/amazon/samconfig.toml
_/amazon/.aws-sam
*.tar
*.tgz
examples/**/package-lock.json
examples/**/.serverless

View File

View File

@ -0,0 +1,30 @@
const puppeteer = require("puppeteer-core");
const chromium = require('@sparticuz/chromium');
const handler = async () => {
try {
const browser = await puppeteer.launch({
args: chromium.args,
defaultViewport: chromium.defaultViewport,
executablePath: await chromium.executablePath(),
headless: chromium.headless,
ignoreHTTPSErrors: true,
});
const page = await browser.newPage();
await page.goto("https://www.example.com", { waitUntil: "networkidle0" });
console.log("Chromium:", await browser.version());
console.log("Page Title:", await page.title());
await page.close();
await browser.close();
} catch (error) {
throw new Error(error.message);
}
};
handler();

View File

@ -0,0 +1,17 @@
{
"name": "chromium-production-dependency",
"version": "0.0.0",
"description": "This package demonstrates using @sparticuz/chromium as a production dependency. WARNING: This package is over 50 megabytes and will likely not deploy using anything other than self-host",
"license": "ISC",
"author": {
"name": "Kyle McNally"
},
"main": "index.js",
"scripts": {
"test": "node index.js"
},
"dependencies": {
"@sparticuz/chromium": "110.0.0",
"puppeteer-core": "19.6.3"
}
}

View File

View File

@ -0,0 +1,30 @@
const puppeteer = require("puppeteer-core");
const chromium = require('@sparticuz/chromium');
module.exports = {
handler: async () => {
try {
const browser = await puppeteer.launch({
args: chromium.args,
defaultViewport: chromium.defaultViewport,
executablePath: await chromium.executablePath(),
headless: chromium.headless,
ignoreHTTPSErrors: true,
});
const page = await browser.newPage();
await page.goto("https://www.example.com", { waitUntil: "networkidle0" });
console.log("Chromium:", await browser.version());
console.log("Page Title:", await page.title());
await page.close();
await browser.close();
} catch (error) {
throw new Error(error.message);
}
}
};

View File

@ -0,0 +1,21 @@
{
"name": "serverless-with-lambda-layer",
"version": "0.0.0",
"description": "This package demonstrates using @sparticuz/chromium as a devDependency with a layer that contains the binaries",
"license": "ISC",
"author": {
"name": "Kyle McNally"
},
"main": "index.js",
"scripts": {
"deploy": "sls deploy",
"test": "sls invoke --function chromium-test --log"
},
"dependencies": {
"puppeteer-core": "19.6.3"
},
"devDependencies": {
"@sparticuz/chromium": "110.0.0",
"serverless": "^3.27.0"
}
}

View File

@ -0,0 +1,19 @@
service: sls-with-layer
provider:
name: aws
runtime: nodejs18.x
stage: dev
region: us-east-1
timeout: 300
functions:
chromium-test:
handler: index.handler
layers:
- !Ref ChromiumtestLambdaLayer
layers:
chromiumtest:
package:
artifact: ../../chromium.zip

View File