【发布时间】:2018-07-17 17:21:19
【问题描述】:
我尝试在我的serverless 项目上使用 DialogFlow(API.AI 或 Google Cloud Dialogflow API),但问题是我找不到将 google 凭据 json 文件推送到无服务器端的任何解决方案。我关注了this tutorial(它在谷歌云网站上),它在我的本地工作正常,但在 lambda 上不能正常工作。我什至尝试从 webpack 复制文件,但它仍然无法正常工作。对于 DialogFlow,我使用的是dialogflow v2 nodejs library。
--- 编辑
我在 lambda 上收到此错误,这与我认为找不到 json 文件有关,因为我没有使用此模块(dialogFlow 正在使用)
(拒绝 id:2):错误:找不到模块 '/var/task/node_modules/grpc/src/node/extension_binary/node-v48-linux-x64-glibc/grpc_node.node' em>
--- 编辑结束
node.js: 6.x
无服务器:1.26
====
serverless.yml
service: test-dialogflow-svc
plugins:
- serverless-webpack
- serverless-plugin-common-excludes
- serverless-offline
- serverless-offline-scheduler
package:
individually: true
include:
- googleCredentials.json
custom:
webpackIncludeModules: true
serverless-offline:
port: 3000
provider:
name: aws
runtime: nodejs6.10
stage: dev
region: eu-west-2
memorySize: 128
timeout: 5
environment:
GOOGLE_APPLICATION_CREDENTIALS: './googleCredentials.json'
functions:
hello:
handler: src/handlers/helloworld.handler
events:
- http:
path: hello
method: get
package:
include:
- googleCredentials.json
webpack.config.js
const path = require('path');
const slsw = require('serverless-webpack');
const nodeExternals = require('webpack-node-externals');
const WebpackPluginCopy = require('webpack-plugin-copy');
module.exports = {
entry: slsw.lib.entries,
target: 'node',
resolve: {
extensions: ['.js', '.json', '.ts', '.tsx']
},
externals: [nodeExternals()],
module: {
rules: [
{
test: /\.ts(x?)$/,
use: [
{
loader: 'awesome-typescript-loader'
}
]
}
]
},
plugins: [ // I tried to copy file with webpack as well
new WebpackPluginCopy([{
copyPermissions: true,
from: './googleCredentials.json'
}])
],
output: {
libraryTarget: 'commonjs',
path: path.join(__dirname, '.webpack'),
filename: '[name].js'
}
};
【问题讨论】:
-
"它在我的本地上正常工作,但在 lambda 上却不行。" - 你得到什么错误?
-
您在上传到无服务器平台时是否复制了“./googleCredentials.json”文件?
-
嘿@rsp,我收到此错误:“(拒绝 id:2):错误:找不到模块 '/var/task/node_modules/grpc/src/node/extension_binary/node- v48-linux-x64-glibc/grpc_node.node'" 我也用这个信息更新了问题
-
@matthewayne,我没有诚实地尝试它,因为我正在尝试使用无服务器框架找到解决方案。我不想手动上传 lambda 函数。但我会测试看看结果;)
-
@the_bluescreen 您能解释一下您是如何解决 Google 凭据 .json 文件的问题的吗?您看到的第二个错误是由 gRPC 节点本机 c++ 模块引起的。 aws.amazon.com/blogs/compute/nodejs-packages-in-lambdagithub.com/grpc/grpc-node
标签: node.js amazon-web-services google-cloud-platform serverless-framework dialogflow-es