Search code examples
node.jshttpelasticsearchaws-lambdaamazon-kinesis-firehose

How to execute HTTP DELETE request in AWS Lambda Nodejs function


I am trying to create an AWS Lambda transform function for a Firehose stream that sends records directly to an Elasticsearch cluster.

Currently, there is no way to specify an ES document id in a Firehose stream record, so all records, even duplicates, are inserted. However, Firehose does support transformation functions hosted in Lambda, which gave me an idea:

My solution is to create a Lambda transform function that executes a DELETE request to Elasticsearch for every record during transformation, then returning all records unmodified, thereby achieving "delete-insert" behaviour (I am ok with the record disappearing for a short period).

However, I know very little about Nodejs and even though this is such a simple thing, I can't figure out how to do it.

Is there a Node package available to Lambda that I can use to do this? (Preferably an AWS Elasticsearch API, but a simple HTTP package would do).

Do I have to package up some other module to get this done?

Can something like Apex help me out here? My preferred language is Go, but so far I have been unable to get apex functions to execute or log anything to Cloudwatch...

Thanks in advance.


Solution

  • It seems a simple task to do, so I guess no framework is needed.

    A few lines of code in Node.js would get the things done. There are two packages that can help you:

    The API doc: https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html