awsConfig passed not being used
Munawwar opened this issue · 1 comments
Hi. First off, nice work with the library.
I couldn't get the library working though. It seems that the AmazonConnection constructor doesn't get the awsConfig at all (when using elastic's 6.x npm module)
Using aws-elasticsearch-connector 8.2.0
and @elastic/elasticsearch 6.8.6
Code
const { Client: ElasticsearchClient } = require('@elastic/elasticsearch');
const { AmazonConnection } = require('aws-elasticsearch-connector');
new ElasticsearchClient({
Connection: AmazonConnection,
awsConfig: {
credentials: {
accessKeyId: 'accessId',
secretAccessKey: 'secretKey',
sessionToken: '', // optional
},
region: 'eu-west-1',
},
node: 'https://my-es-app-asdadkjaskldjakld.eu-west-1.es.amazonaws.com/',
});
I modified your constructor to console.log the options passed
class AmazonConnection extends Connection {
constructor (options) {
super(options)
console.log('AmazonConnection constructor options', options);
this.awsConfig = options.awsConfig || AWS.config
}
Output
AmazonConnection constructor options {
url: URL {
href: 'https://my-es-app-asdadkjaskldjakld.eu-west-1.es.amazonaws.com/',
origin: 'https://my-es-app-asdadkjaskldjakld.eu-west-1.es.amazonaws.com',
protocol: 'https:',
username: '',
password: '',
host: 'my-es-app-asdadkjaskldjakld.eu-west-1.es.amazonaws.com',
hostname: 'my-es-app-asdadkjaskldjakld.eu-west-1.es.amazonaws.com',
port: '',
pathname: '/',
search: '',
searchParams: URLSearchParams {},
hash: ''
},
ssl: null,
agent: null
}
^ options.awsConfig is missing. Seems like @elastic/elasticsearch didn't pass it
Did you try the third option listed in the README?
With asynchronous or refreshing credentials from AWS
When reading AWS credentials from an IAM role or an EC2/ECS profile, the credentials
will be retrieved and refreshed automatically. In this case you'll need to use the
bundledAmazonTransport
transport which will call AWS.Config.getCredentials()
before each ElasticSearch request to ensure that the latest credentials are used.const { Client } = require('@elastic/elasticsearch'); const { AmazonConnection, AmazonTransport } = require('aws-elasticsearch-connector'); const client = new Client({ node: 'my-elasticsearch-cluster.us-east-1.es.amazonaws.com', Connection: AmazonConnection, Transport: AmazonTransport });