[英]Serverless async function error
我正在使用无服务器来运行 lambda 函数。
在尝试执行sls invoke local --function myFunction
时遇到问题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)
无服务器配置看起来像这样。
无服务器.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-webpack
webpack.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
一切似乎工作正常,直到功能路线被击中。
sls invoke local
通过模拟 AWS Lambda 环境在sls invoke local
运行您的代码。 因此,请确保您的开发机器中安装了节点 8及更高版本,以获得异步等待本机支持。 在本地运行node --version
以检查您的节点开发版本。
请确保您在estlintrc.js
上使用 ECMA 脚本 8。
然后它将正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.