Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

aws_es

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aws_es

Creates a clone of the http class that signs each request before its sent.

  • 1.1.2
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Minimal AWS Elasticsearch connector

Creates a clone of the http class that signs each request before its sent.

Usage:

var elasticsearch = require('elasticsearch');
require('aws_es')(elasticsearch);

var client = new elasticsearch.Client({
  host : 'xxxxx.es.amazonaws.com',
  amazonES: {
    region : 'us-east-1',
    accessKey : 'XXXX',
    secretKey : 'XXXX'
  }
})

Config variables service, region, accessKey and secretKey can be defined in an amazonES object at client creation. Alternatively, service defaults to 'es', region defaults to 'us-east-1' and the keys default to environment variables: AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY

The complete code is as follows:

var aws4 = require('aws4');

module.exports = function(es) {
  var pool = es.ConnectionPool,
      http = pool.connectionClasses.http;

  var aws = function() { http.apply(this,arguments); };
  require('util').inherits(aws,http);

  aws.prototype.createAgent = function(config) {
    this._amazonES = config.amazonES || {};
    http.prototype.createAgent.call(this,config);
  };

  aws.prototype.makeReqParams = function (_params) {
    var params = http.prototype.makeReqParams.call(this,_params);
    params.body = _params.body;
    params.headers = params.headers || {};
    params.headers['Content-Type'] = params.headers['Content-Type'] || 'application/json';
    if (params.gzip === undefined) params.gzip = true;

    var config = this._amazonES;
    params.service =  config.service || 'es';
    params.region = config.region || 'us-east-1';
    
    aws4.sign(params,{
      accessKeyId: config.accessKey || process.env.AWS_ACCESS_KEY_ID,
      secretAccessKey: config.secretKey || process.env.AWS_SECRET_ACCESS_KEY
    });
    
    return params;
  };

  pool.defaultConnectionClass = 'aws';
  pool.connectionClasses.aws = aws;
  return es;
};

FAQs

Package last updated on 03 Mar 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc