我正在使用serverless来运行lambda函数。
尝试执行sls invoke local --function myFunction时面临的问题
exports.myFunction = async (event) => {
^
SyntaxError: Unexpected token (
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)无服务器配置如下所示。
serverless.yaml
service: myService
provider:
name: aws
runtime: nodejs8.10
stage: ${opt:stage, 'dev'}
region: eu-west-1
environment:
CUSTOM_ENV: ${opt:stage, 'dev'}
functions:
myFunction:
handler: index.myFunction
events:
- http:
cors: true
path: /{proxy+}
method: POST
plugins:
- serverless-offline
- serverless-webpackwebpack.config.js
const slsw = require("serverless-webpack");
const nodeExternals = require("webpack-node-externals");
const path = require('path');
module.exports = {
entry: slsw.lib.entries,
target: "node",
// Generate sourcemaps for proper error messages
devtool: 'source-map',
mode: slsw.lib.webpack.isLocal ? "development" : "production",
optimization: {
// We no not want to minimize our code.
minimize: false
},
performance: {
// Turn off size warnings for entry points
hints: false
},
};在运行命令sls offline start时
在命中函数路由之前,一切似乎都很正常。
发布于 2018-06-11 10:16:23
sls invoke local 通过模拟AWS Lambda环境在本地运行您的代码。因此,请确保您在开发机器上安装了node 8和更高版本,以获得异步等待本机支持。在本地运行node --version以检查您的节点开发版本。
发布于 2020-10-13 10:49:44
请确保您在estlintrc.js上使用的是ECMA script 8。
然后它就可以正常工作了。
https://stackoverflow.com/questions/50735838
复制相似问题