Trying to index some data in elasticsearch using AWS Lambda. Stack Trace
TypeError [ERR_INVALID_ARG_TYPE]: The "key" argument must be one of type string, TypedArray, or DataView at new Hmac (internal/crypto/hash.js:84:11) at Object.createHmac (crypto.js:122:10) at Object.hmac (/home/projects/serverless-todo-app/.webpack/service/src/indexer/createIndex.js:698:30) at Object.getSigningKey (/home/projects/serverless-todo-app/.webpack/service/src/indexer/createIndex.js:7109:8) at V4.signature (/home/projects/serverless-app/.webpack/service/src/indexer/createIndex.js:12708:36) at V4.authorization (/home/projects/serverless-app/.webpack/service/src/indexer/createIndex.js:12703:36) at V4.addAuthorization (/home/projects/serverless-app/.webpack/service/src/indexer/createIndex.js:12645:12) at ElasticsearchService.put (/home/projects/serverless-app/.webpack/service/src/indexer/createIndex.js:8150:12) at process (/home/projects/serverless-app/.webpack/service/src/indexer/createIndex.js:8115:24) at BbPromise (/usr/local/lib/node_modules/serverless/lib/plugins/aws/invokeLocal/index.js:567:30) at AwsInvokeLocal.invokeLocalNodeJs (/usr/local/lib/node_modules/serverless/lib/plugins/aws/invokeLocal/index.js:521:12) at AwsInvokeLocal.invokeLocal (/usr/local/lib/node_modules/serverless/lib/plugins/aws/invokeLocal/index.js:152:19) From previous event: at Object.invoke:local:invoke [as hook] (/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());
Trying to index some data in elastisearch using AWS Lambda.
You should have an endpoint and have initiated your request. You can do it like below and also check the link pasted after the code.
/* == 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());
Inamazon-elasticsearch-lambda-samples check lines 45-55 (Sorry I cannot comment because of low reputation)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With