# aws-elasticsearch-connector

> A tiny Amazon Signature Version 4 connection class for @elastic/elasticsearch, for compatibility with AWS Elasticsearch and IAM authentication.

Latest version **9.2.0** (published 2022-05-16) · MIT license · 37.4K weekly downloads

## Install

```sh
npm install aws-elasticsearch-connector
pnpm add aws-elasticsearch-connector
yarn add aws-elasticsearch-connector
bun add aws-elasticsearch-connector
```

## Health

**Score 35/100 (D)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 9.2.0 |
| Published | 2022-05-16 |
| First published | 2019-08-16 |
| Weekly downloads | 37.4K |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >= 10 |
| Dependencies | 1 |
| Unpacked size | 17.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 76 |
| Author | Jonathon Hill |
| Maintainers | compwright |
| Keywords | elasticsearch, aws-es, aws, aws4, amazon, es, http, connector, extension, sign, http-aws-es, HttpConnection |

## Links

- npm: https://www.npmjs.com/package/aws-elasticsearch-connector
- Repository: https://github.com/compwright/aws-elasticsearch-connector
- Homepage: https://github.com/compwright/aws-elasticsearch-connector#readme
- Issues: https://github.com/compwright/aws-elasticsearch-connector/issues
- npm.io page: https://npm.io/package/aws-elasticsearch-connector

## Dependencies (1)

- [aws4](https://npm.io/package/aws4.md) ^1.11.0

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [vest](https://npm.io/package/vest.md) — 50.1K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads

## Recent versions

- 9.2.0 (latest) — 2022-05-16
- 9.1.0 — 2022-05-16
- 9.0.3 — 2021-01-23
- 9.0.1 — 2020-11-17
- 9.0.0 — 2020-07-04
- 8.3.0 — 2020-07-04
- 8.2.0 — 2019-10-25
- 8.1.3 — 2019-09-04
- 8.1.2 — 2019-09-03
- 8.1.1 — 2019-08-31
- 8.1.0 — 2019-08-31
- 8.0.0 — 2019-08-17
- 7.0.0 — 2019-08-16

## README

# aws-elasticsearch-connector

[![Build Status](https://travis-ci.org/compwright/aws-elasticsearch-connector.png?branch=master)](https://travis-ci.org/compwright/aws-elasticsearch-connector)
[![Code Climate](https://codeclimate.com/github/compwright/aws-elasticsearch-connector/badges/gpa.svg)](https://codeclimate.com/github/compwright/aws-elasticsearch-connector)
[![Test Coverage](https://codeclimate.com/github/compwright/aws-elasticsearch-connector/badges/coverage.svg)](https://codeclimate.com/github/compwright/aws-elasticsearch-connector/coverage)
[![Dependency Status](https://img.shields.io/david/compwright/aws-elasticsearch-connector.svg?style=flat-square)](https://david-dm.org/compwright/aws-elasticsearch-connector)
[![Download Status](https://img.shields.io/npm/dm/aws-elasticsearch-connector.svg?style=flat-square)](https://www.npmjs.com/package/aws-elasticsearch-connector)

A tiny [Amazon Signature Version 4](https://www.npmjs.com/package/aws4) connection class for the official [Elasticsearch Node.js client](https://www.npmjs.com/package/elasticsearch), for compatibility with AWS Elasticsearch and IAM authentication.

Supports AWS SDK global or specific configuration instances (AWS.Config), including asyncronous credentials from IAM roles and credential refreshing.

## Installation

```bash
npm install --save aws-elasticsearch-connector @elastic/elasticsearch aws-sdk
```

## Example usage

### Using global configuration

```javascript
const { Client } = require("@elastic/elasticsearch");
const AWS = require("aws-sdk");
const createAwsElasticsearchConnector = require("aws-elasticsearch-connector");

// (Optional) load profile credentials from file
AWS.config.update({
  profile: "my-profile",
});

const client = new Client({
  ...createAwsElasticsearchConnector(AWS.config),
  node: "https://my-elasticsearch-cluster.us-east-1.es.amazonaws.com",
});
```

### Using specific configuration

```javascript
const { Client } = require("@elastic/elasticsearch");
const AWS = require("aws-sdk");
const createAwsElasticsearchConnector = require("aws-elasticsearch-connector");

const awsConfig = new AWS.Config({
  // Your credentials and settings here, see
  // https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Config.html#constructor-property
});

const client = new Client({
  ...createAwsElasticsearchConnector(awsConfig),
  node: "https://my-elasticsearch-cluster.us-east-1.es.amazonaws.com",
});
```

### Using aws-sdk v3

```javascript
const { STSClient, AssumeRoleCommand } = require("@aws-sdk/client-sts");
const { Client } = require("@elastic/elasticsearch");
const createAwsElasticsearchConnector = require("./src/index.js");

async function ping() {
  const creds = await assumeRole(
    "arn:aws:iam::0123456789012:role/Administrator",
    "us-east-1"
  );
  const client = new Client({
    ...createAwsElasticsearchConnector({
      region: "us-east-1",
      credentials: creds,
    }),
    node: "https://my-elasticsearch-cluster.us-east-1.es.amazonaws.com",
  });
  const response = await client.ping();
  console.log(`Got Response`, response);
}

async function assumeRole(roleArn, region) {
  const client = new STSClient({ region });
  const response = await client.send(
    new AssumeRoleCommand({
      RoleArn: roleArn,
      RoleSessionName: "aws-es-connection",
    })
  );
  return {
    accessKeyId: response.Credentials.AccessKeyId,
    secretAccessKey: response.Credentials.SecretAccessKey,
    sessionToken: response.Credentials.SessionToken,
  };
}
```

## Test

```bash
npm test

# Run integration tests against a real endpoint
AWS_PROFILE=your-profile npm run test:integration -- \
  --endpoint https://my-elasticsearch-cluster.us-east-1.es.amazonaws.com
```

---
_Source: https://npm.io/package/aws-elasticsearch-connector · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
