aws-elasticsearch-connector
A tiny Amazon Signature Version 4 connection class for the official Elasticsearch Node.js client, for compatibility with AWS Elasticsearch and IAM authentication.
For legacy Elasticsearch.js 16.x support, use version 7.x of this library.
Installation
npm install --save aws-elasticsearch-connector @elastic/elasticsearch aws-sdk
Example usage
With specific credentials
const { Client } = require('@elastic/elasticsearch');
const client = new Client({
node: 'my-elasticsearch-cluster.us-east-1.es.amazonaws.com'
Connection: require('aws-elasticsearch-connector'),
awsConfig: {
credentials: {
accessKeyId: 'foo',
secretAccessKey: 'bar',
sessionToken: 'baz' // optional
}
}
});
With credentials from AWS.Config
const AWS = require('aws-sdk');
const { Client } = require('@elastic/elasticsearch');
// Load AWS profile credentials
AWS.config.update({
profile: 'my-profile'
});
const client = new Client({
node: 'my-elasticsearch-cluster.us-east-1.es.amazonaws.com'
Connection: require('aws-elasticsearch-connector')
});
With credentials from the environment
AWS_ACCESS_KEY_ID=foo # alias: AWS_ACCESS_KEY
AWS_SECRET_ACCESS_KEY=bar # alias: AWS_SECRET_KEY
AWS_SESSION_TOKEN=baz
const { Client } = require('@elastic/elasticsearch');
const client = new Client({
node: 'my-elasticsearch-cluster.us-east-1.es.amazonaws.com'
Connection: require('aws-elasticsearch-connector'),
});
Test
npm test
# Run integration tests against a real endpoint
AWS_PROFILE=your-profile npm run test:integration -- \
--endpoint https://amazon-es-host.us-east-1.es.amazonaws.com