aws-elasticsearch-connector
Advanced tools
Comparing version 9.0.3 to 9.1.0
# Changelog | ||
## [v9.0.3](https://github.com/compwright/aws-elasticsearch-connector/tree/v9.0.3) (2021-01-23) | ||
[Full Changelog](https://github.com/compwright/aws-elasticsearch-connector/compare/v9.0.1...v9.0.3) | ||
**Closed issues:** | ||
- AWS ElasticSearch Custom domain names not connecting [\#24](https://github.com/compwright/aws-elasticsearch-connector/issues/24) | ||
- aws sigv4 signature not match when Content-Length exist in the request before applying AmazonConnection [\#22](https://github.com/compwright/aws-elasticsearch-connector/issues/22) | ||
**Merged pull requests:** | ||
- Set region when signing request if provided in the AWS config object [\#26](https://github.com/compwright/aws-elasticsearch-connector/pull/26) ([chsing-br](https://github.com/chsing-br)) | ||
## [v9.0.1](https://github.com/compwright/aws-elasticsearch-connector/tree/v9.0.1) (2020-11-17) | ||
@@ -4,0 +17,0 @@ |
{ | ||
"name": "aws-elasticsearch-connector", | ||
"version": "9.0.3", | ||
"version": "9.1.0", | ||
"description": "A tiny Amazon Signature Version 4 connection class for @elastic/elasticsearch, for compatibility with AWS Elasticsearch and IAM authentication.", | ||
@@ -58,3 +58,3 @@ "repository": "https://github.com/compwright/aws-elasticsearch-connector", | ||
"@elastic/elasticsearch": ">=6", | ||
"aws-sdk": "^2.793.0" | ||
"aws-sdk": "^2.831.0" | ||
}, | ||
@@ -65,6 +65,6 @@ "devDependencies": { | ||
"minimist": "^1.2.5", | ||
"mocha": "^8.2.1", | ||
"nyc": "^15.1.0", | ||
"mocha": "*", | ||
"nyc": "*", | ||
"standard": "*" | ||
} | ||
} |
@@ -24,15 +24,15 @@ # aws-elasticsearch-connector | ||
```javascript | ||
const { Client } = require('@elastic/elasticsearch') | ||
const AWS = require('aws-sdk') | ||
const createAwsElasticsearchConnector = require('aws-elasticsearch-connector') | ||
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' | ||
}) | ||
profile: "my-profile", | ||
}); | ||
const client = new Client({ | ||
...createAwsElasticsearchConnector(AWS.config), | ||
node: 'https://my-elasticsearch-cluster.us-east-1.es.amazonaws.com' | ||
}) | ||
node: "https://my-elasticsearch-cluster.us-east-1.es.amazonaws.com", | ||
}); | ||
``` | ||
@@ -43,5 +43,5 @@ | ||
```javascript | ||
const { Client } = require('@elastic/elasticsearch') | ||
const AWS = require('aws-sdk') | ||
const createAwsElasticsearchConnector = require('aws-elasticsearch-connector') | ||
const { Client } = require("@elastic/elasticsearch"); | ||
const AWS = require("aws-sdk"); | ||
const createAwsElasticsearchConnector = require("aws-elasticsearch-connector"); | ||
@@ -51,10 +51,49 @@ const awsConfig = new AWS.Config({ | ||
// 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' | ||
}) | ||
```` | ||
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 | ||
@@ -61,0 +100,0 @@ |
@@ -20,12 +20,21 @@ const { Transport } = require('@elastic/elasticsearch') | ||
// Promise support | ||
if (typeof callback === 'undefined') { | ||
return awaitAwsCredentials(awsConfig) | ||
.then(() => super.request(params, options)) | ||
// check if getCredentials exists, if so this is an aws-sdk v2 global config object | ||
if (typeof awsConfig.getCredentials !== 'function') { | ||
if (typeof callback === 'undefined') { | ||
return super.request(params, options) | ||
} else { | ||
super.request(params, options, callback) | ||
} | ||
} else { | ||
// Promise support | ||
if (typeof callback === 'undefined') { | ||
return awaitAwsCredentials(awsConfig) | ||
.then(() => super.request(params, options)) | ||
} | ||
// Callback support | ||
awaitAwsCredentials(awsConfig) | ||
.then(() => super.request(params, options, callback)) | ||
.catch(callback) | ||
} | ||
// Callback support | ||
awaitAwsCredentials(awsConfig) | ||
.then(() => super.request(params, options, callback)) | ||
.catch(callback) | ||
} | ||
@@ -32,0 +41,0 @@ } |
17495
78
105