Mar*_*ask 0 node.js async-await 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)
Run Code Online (Sandbox Code Playgroud)
无服务器配置看起来像这样。
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-webpack
Run Code Online (Sandbox Code Playgroud)
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
},
};
Run Code Online (Sandbox Code Playgroud)
运行命令时 sls offline start
一切正常,直到找到功能路由为止。
小智 8
sls invoke local 通过模拟AWS Lambda环境在本地运行代码。因此,请确保在开发机中安装了8号及更高版本的节点,以便异步等待本机支持。在node --version本地运行以检查您的节点开发版本。
| 归档时间: |
|
| 查看次数: |
449 次 |
| 最近记录: |