-
Notifications
You must be signed in to change notification settings - Fork 507
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added Sigv4 Section to JavaScript Client #1796
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -141,6 +141,68 @@ async function search() { | |
search().catch(console.log); | ||
``` | ||
|
||
## Authenticate with Amazon OpenSearch Service - AWS Sigv4 | ||
|
||
### Using AWS V2 SDK | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. Suggest: Use the following code to authenticate with AWS V2 SDK. |
||
```javascript | ||
const AWS = require('aws-sdk'); // V2 SDK. | ||
const { Client } = require('@opensearch-project/opensearch'); | ||
const { AwsSigv4Signer } = require('@opensearch-project/opensearch/aws'); | ||
|
||
const client = new Client({ | ||
...AwsSigv4Signer({ | ||
region: 'us-east-1', | ||
// Must return a Promise that resolve to an AWS.Credentials object. | ||
// This function is used to acquire the credentials when the client start and | ||
// when the credentials are expired. | ||
// The Client will refresh the Credentials only when they are expired. | ||
// With AWS SDK V2, Credentials.refreshPromise is used when available to refresh the credentials. | ||
|
||
// Example with AWS SDK V2: | ||
getCredentials: () => | ||
new Promise((resolve, reject) => { | ||
// Any other method to acquire a new Credentials object can be used. | ||
AWS.config.getCredentials((err, credentials) => { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(credentials); | ||
} | ||
}); | ||
}), | ||
}), | ||
node: "https://search-xxx.region.es.amazonaws.com", // OpenSearch domain URL | ||
}); | ||
``` | ||
|
||
### Using AWS V3 SDK | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. Suggest: Use the following code to authenticate with AWS V3 SDK. |
||
|
||
```javascript | ||
const { defaultProvider } = require("@aws-sdk/credential-provider-node"); // V3 SDK. | ||
const { Client } = require('@opensearch-project/opensearch'); | ||
const { AwsSigv4Signer } = require('@opensearch-project/opensearch/aws'); | ||
|
||
const client = new Client({ | ||
...AwsSigv4Signer({ | ||
region: 'us-east-1', | ||
// Must return a Promise that resolve to an AWS.Credentials object. | ||
// This function is used to acquire the credentials when the client start and | ||
// when the credentials are expired. | ||
// The Client will refresh the Credentials only when they are expired. | ||
// With AWS SDK V2, Credentials.refreshPromise is used when available to refresh the credentials. | ||
|
||
// Example with AWS SDK V3: | ||
getCredentials: () => { | ||
// Any other method to acquire a new Credentials object can be used. | ||
const credentialsProvider = defaultProvider(); | ||
return credentialsProvider(); | ||
}, | ||
}), | ||
node: "https://search-xxx.region.es.amazonaws.com", // OpenSearch domain URL | ||
}); | ||
``` | ||
|
||
## Circuit breaker | ||
|
||
The `memoryCircuitBreaker` option can be used to prevent errors caused by a response payload being too large to fit into the heap memory available to the client. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we add a simple sentence to separate the headings? Suggest:
Use the following code to authenticate with Amazon OpenSearch Service.