# aws-elasticsearch-js

> Use elasticsearch-js with Amazon ES

Latest version **1.0.3** (published 2021-04-10) · MIT license · 0 weekly downloads

## Install

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

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2021-04-10 |
| First published | 2021-03-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 9.5 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 14 |
| Author | Geoff Wagstaff |
| Maintainers | thedeveloper |
| Keywords | aws, elasticsearch, js, elastic, connector, sign, iam, amazon, es, signer |

## Links

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

## Dependencies (4)

- [pump](https://npm.io/package/pump.md) ^3.0.0
- [debug](https://npm.io/package/debug.md) ^4.3.1
- [aws-sdk](https://npm.io/package/aws-sdk.md) ^2.873.0
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) ^7.12.0

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.0.3 (latest) — 2021-04-10
- 1.0.2 — 2021-03-26
- 1.0.1 — 2021-03-26
- 1.0.0 — 2021-03-26

## README

# AWS Elasticsearch
Use Elastic's official [elasticsearch-js](https://github.com/elastic/elasticsearch-js) with Amazon Elasticsearch.

[![npm version](https://badge.fury.io/js/aws-elasticsearch-js.svg)](https://badge.fury.io/js/aws-elasticsearch-js)

# Install
    npm i aws-elasticsearch-js

# Usage
```js
const elasticsearch = require('@elastic/elasticsearch');
const { createConnector } = require('aws-elasticsearch-js');

const region = process.env.AWS_REGION || 'us-east-1';
const domain = 'https://domain-1-abc123.region.es.amazonaws.com/';

const client = new elasticsearch.Client({
  nodes: [ domain ],
  Connection: createConnector({ region })
});

// use in the normal way
async function example() {
  await client.index({ index: 'test', doc: { test: 'hello' } });
  await client.indices.refresh();
  let result = await client.search({ index: 'test' });
}
example();
```

# Credentials
The connector will use AWS credentials from the environment.

If you have another method of loading / refreshing credentials, you can pass them using `getCreds`:
```js
// heads up: this is called on every request
const getCreds = cb => {
  // load creds from somewhere...
  const credentials = { accessKeyId, secretAccessKey };
  // or credentials = { sessionToken }
  const err = null; // if you give an error, the request will abort
  cb(err, credentials);
};
createConnector({ region, getCreds });
```

# Options
```js
// options and example values
const options = {
  region: 'us-east-1', // AWS region (defaults to process.env.AWS_REGION)
  getCreds: cb => cb(err, credentials) // see above
};
createConnector(options);
```

# Test
```bash
# make sure aws creds are defined in the environment
AWS_REGION=us-east-1 \
AWS_ES_DOMAIN=https://domain-1-abc123.region.es.amazonaws.com/ \
npm test
```

# Troubleshooting
If you get status code 403:

* check your code is running with the right role / aws access credentials.
* make sure your role / user is authorised in the domain's [access policy](https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/es-ac.html), or choose "allow open access to the domain" [if your domain is in VPC](https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/es-vpc.html#es-vpc-security).
* make sure you've allowed your user/role if you're using aws elasticsearch's [security and access management](https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/fgac.html#fgac-access-control).
  * One quick way to do this is go to Kibana > Security > roles > all_access > mapped users > manage mapping > users/backend roles and add the ARNs there.

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