Node.js 无服务器AWS上的Google凭据json文件
我尝试在我的项目中使用DialogFlow(API.AI或Google Cloud DialogFlow API),但问题是我找不到任何将Google凭证json文件推送到无服务器端的解决方案。我遵循了(在谷歌云网站上),它在我的本地电脑上正常工作,但在lambda电脑上没有。我甚至试着从网页上复制文件,但还是不起作用。对于DialogFlow,我使用 ——编辑 我在lambda上遇到了这个错误,它与找不到json文件有关,我想是因为我没有使用这个模块(dialogFlow正在使用) (拒绝id:2):错误:找不到模块“/var/task/node_modules/grpc/src/node/extension_binary/node-v48-linux-x64-glibc/grpc_node.node” ——编辑结束 node.js:6.x 无服务器:1.26 ==== serverless.ymlNode.js 无服务器AWS上的Google凭据json文件,node.js,amazon-web-services,google-cloud-platform,serverless-framework,dialogflow-es,Node.js,Amazon Web Services,Google Cloud Platform,Serverless Framework,Dialogflow Es,我尝试在我的项目中使用DialogFlow(API.AI或Google Cloud DialogFlow API),但问题是我找不到任何将Google凭证json文件推送到无服务器端的解决方案。我遵循了(在谷歌云网站上),它在我的本地电脑上正常工作,但在lambda电脑上没有。我甚至试着从网页上复制文件,但还是不起作用。对于DialogFlow,我使用 ——编辑 我在lambda上遇到了这个错误,它与找不到json文件有关,我想是因为我没有使用这个模块(dialogFlow正在使用) (拒绝id
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'
}
};
这个问题的答案由两部分组成:
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'
}
};
2) DialogFlow节点客户机使用具有。对于谷歌云平台产品的所有其他节点客户端,如
您需要通过DOCKER或EC2.在//P>上在您的计算机上在Amazon Linux实例上构建本机C++模块。
RESTJSON API而不是gRPC由于本地C++模块很烦人,所有谷歌云平台节点客户端也将30MB添加到Server Neal.zip包中,您可能希望避免GRPC客户端,查找/编写一个调用该HTTP客户端的HTTP客户端。HTTP上的JSON具有比gRPC更高的延迟,但这并不重要,除非有许多层的微服务相互调用
将来,节点GRPC客户端可能不使用C++模块,使用JavaScript和权重远远小于30MB,但在编写时,除了“./P>”之外,没有承诺的迹象“它在我的本地上工作,而不是在lambda上工作。”-您遇到了什么错误?在上传到无服务器平台时是否复制了“/googleCredentials.json”文件?嘿@rsp,我遇到了这个错误:“(拒绝id:2):错误:找不到模块“/var/task/node_modules/grpc/src/node/extension_binary/node-v48-linux-x64-glibc/grpc_node.node”我还更新了这个问题info@matthewayne,我并没有诚实地尝试它,因为我正在尝试用无服务器框架寻找解决方案。我不想手动上传lambda函数。但我会测试一下,看看结果;)@你能解释一下你是如何用Google credential.json文件解决这个问题的吗?你看到的第二个错误是由GRPC节点本地C++模块引起的。