Hello,
I succeeded to call chromeless from nodejs 6.x application to local Chrome and it worked great.
Also from a nodejs 6.x application to remote Chrome via proxy, and it worked great
However, I am trying to run the simple example from a local Lambda function to local Chrome using sam local.
This is my code on "index.js" of the Lambda function:
```
'use strict'
var moment = require('moment')
var Chromeless = require('chromeless')
// A simple hello world Lambda function
exports.handler = (event, context, callback) => {
console.log('LOG: Name is ' + event.name);
var now = moment();
console.log(now.format("dddd, MMMM Do YYYY, h:mm:ss a"))
var run = async => {
const chromeless = new Chromeless()
const screenshot = await chromeless
.goto('https://www.google.com')
.type('chromeless', 'input[name="q"]')
.press(13)
.wait('#resultStats')
.screenshot()
console.log(screenshot) // prints local file path or S3 url
await chromeless.end()
}
run().catch(console.error.bind(console))
callback(null, "Hello " + event.name);
}
I run it by the following command:
`sam local invoke "HelloChromeless" -e event.json`
And I get the following error:
Syntax error in module 'index': SyntaxError
const screenshot = await chromeless
^^^^^^^^^^
SyntaxError: Unexpected identifier
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:542:28)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
Also the following produce the same:
exports.handler = (event, context, callback) => {
console.log('LOG: Name is ' + event.name);
var now = moment();
console.log(now.format("dddd, MMMM Do YYYY, h:mm:ss a"))
run()
async function run() {
const chromeless = new Chromeless()
const screenshot = await chromeless
.goto('https://www.google.com')
.type('chromeless', 'input[name="q"]')
.press(13)
.wait('#resultStats')
.screenshot()
console.log(screenshot) // prints local file path or S3 url
await chromeless.end()
}
callback(null, "Hello " + event.name);
}
```
What is the solution for it?
If it is too complicated to run a local Lambda function, and only run a Lambda function in AWS with a remote proxy of chromeless, it is an acceptable answer.
I just need an example of a Lambda function calling chromeless via API Gateway (or directly to chrome).
Thanks!
Not an issue with Chromeless; this would be because the latest Node version supported by Lambda does not include support for async/await keywords.
You will need to use Webpack+Babel to transpile as part of your packaging. There is a handy guide available at https://serverless-stack.com/chapters/add-support-for-es6-es7-javascript.html -- try and follow this and it should work.
@danielbergamin Thanks a lot! It realy helped me to be able to call chromeless from AWS Lambda function. I even succeeded to run the Lambda function locally and call the local chrome on my machine. Really great!
As a contribution to the community, I created a skeleton project for calling chromeless from AWS Lambda, from which anyone can start: Calling chromeless from AWS Lambda function
Glad to hear it worked @eitansela, thanks for putting together an example as well.
Hi @danielbergamin , I'm get the same error and still very confused after reading this thread. How am I supposed to use the mentioned page? why is none of this in the README??
https://serverless-stack.com/chapters/add-support-for-es6-es7-javascript.html
Most helpful comment
Not an issue with Chromeless; this would be because the latest Node version supported by Lambda does not include support for async/await keywords.
You will need to use Webpack+Babel to transpile as part of your packaging. There is a handy guide available at https://serverless-stack.com/chapters/add-support-for-es6-es7-javascript.html -- try and follow this and it should work.