pri*_*tam 7 aws-lambda serverless
尝试使用 AWS Lambda 在 elasticsearch 中索引一些数据。堆栈跟踪
TypeError [ERR_INVALID_ARG_TYPE]: 在 Object.createHmac (crypto.js:122:10) 的 new Hmac (internal/crypto/hash.js:84:11) 中,“key”参数必须是 string、TypedArray 或 DataView 类型之一在 Object.hmac (/home/projects/serverless-todo-app/.webpack/service/src/indexer/createIndex.js:698:30) 在 Object.getSigningKey (/home/projects/serverless-todo-app/. webpack/service/src/indexer/createIndex.js:7109:8) 在 V4.signature (/home/projects/serverless-app/.webpack/service/src/indexer/createIndex.js:12708:36) 在 V4。授权 (/home/projects/serverless-app/.webpack/service/src/indexer/createIndex.js:12703:36) 在 V4.addAuthorization (/home/projects/serverless-app/.webpack/service/src/indexer /createIndex.js:12645:12) 在 ElasticsearchService.put (/home/projects/serverless-app/.webpack/service/src/indexer/createIndex.js:8150:12) 在进程 (/home/projects/serverless-app/.webpack/service/src/indexer/createIndex.js:8115:24) 在 BbPromise (/usr /local/lib/node_modules/serverless/lib/plugins/aws/invokeLocal/index.js:567:30) 在 AwsInvokeLocal.invokeLocalNodeJs (/usr/local/lib/node_modules/serverless/lib/plugins/aws/invokeLocal/index .js:521:12) 在 AwsInvokeLocal.invokeLocal (/usr/local/lib/node_modules/serverless/lib/plugins/aws/invokeLocal/index.js:152:19) 来自之前的事件:在 Object.invoke:local:调用 [作为钩子] (/usr/local/lib/node_modules/serverless/lib/plugins/aws/invokeLocal/index.js:34:10)24) 在 BbPromise (/usr/local/lib/node_modules/serverless/lib/plugins/aws/invokeLocal/index.js:567:30) 在 AwsInvokeLocal.invokeLocalNodeJs (/usr/local/lib/node_modules/serverless/lib/ plugins/aws/invokeLocal/index.js:521:12) 在 AwsInvokeLocal.invokeLocal (/usr/local/lib/node_modules/serverless/lib/plugins/aws/invokeLocal/index.js:152:19) 来自之前的事件:在 Object.invoke:local:invoke [as hook] (/usr/local/lib/node_modules/serverless/lib/plugins/aws/invokeLocal/index.js:34:10)24) 在 BbPromise (/usr/local/lib/node_modules/serverless/lib/plugins/aws/invokeLocal/index.js:567:30) 在 AwsInvokeLocal.invokeLocalNodeJs (/usr/local/lib/node_modules/serverless/lib/ plugins/aws/invokeLocal/index.js:521:12) 在 AwsInvokeLocal.invokeLocal (/usr/local/lib/node_modules/serverless/lib/plugins/aws/invokeLocal/index.js:152:19) 来自之前的事件:在 Object.invoke:local:invoke [as hook] (/usr/local/lib/node_modules/serverless/lib/plugins/aws/invokeLocal/index.js:34:10)调用 [作为钩子] (/usr/local/lib/node_modules/serverless/lib/plugins/aws/invokeLocal/index.js:34:10)调用 [作为钩子] (/usr/local/lib/node_modules/serverless/lib/plugins/aws/invokeLocal/index.js:34:10)
const credentials = new AWS.EnvironmentCredentials('AWS');
let signer = new AWS.Signers.V4(this.request, 'es');
signer.addAuthorization(credentials, new Date());
Run Code Online (Sandbox Code Playgroud)
尝试使用 AWS Lambda 在 elastisearch 中索引一些数据。
您应该有一个端点并已发起您的请求。您可以像下面一样执行此操作,并检查代码后粘贴的链接。
/* == Globals == */
var esDomain = {
region: 'us-east-1',
endpoint: 'my-domain-search-endpoint',
index: 'myindex',
doctype: 'mytype'
};
var endpoint = new AWS.Endpoint(esDomain.endpoint);
/*
* The AWS credentials are picked up from the environment.
* They belong to the IAM role assigned to the Lambda function.
* Since the ES requests are signed using these credentials,
* make sure to apply a policy that allows ES domain operations
* to the role.
*/
var creds = new AWS.EnvironmentCredentials('AWS');
var req = new AWS.HttpRequest(endpoint);
req.method = 'POST';
req.path = path.join('/', esDomain.index, esDomain.doctype);
req.region = esDomain.region;
req.headers['presigned-expires'] = false;
req.headers['Host'] = endpoint.host;
req.body = doc;
var signer = new AWS.Signers.V4(req , 'es'); // es: service code
signer.addAuthorization(creds, new Date());
Run Code Online (Sandbox Code Playgroud)
在amazon-elasticsearch-lambda-samples中检查第 45-55 行(抱歉,由于声誉较低,我无法发表评论)
| 归档时间: |
|
| 查看次数: |
7280 次 |
| 最近记录: |