Merge pull request #54 from Sparticuz/feature/examples
This commit is contained in:
commit
58460d821c
|
|
@ -10,3 +10,5 @@ _/amazon/samconfig.toml
|
|||
_/amazon/.aws-sam
|
||||
*.tar
|
||||
*.tgz
|
||||
examples/**/package-lock.json
|
||||
examples/**/.serverless
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
|
@ -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
|
||||
Loading…
Reference in New Issue