Created
December 15, 2022 16:38
-
-
Save gbvanrenswoude/61e8142dcd30fe6de040307b5524ef22 to your computer and use it in GitHub Desktop.
Expand OpenSearch SDK with aws sigv4 signing of requests on the Client using aws-opensearch-connector
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { defaultProvider } from '@aws-sdk/credential-provider-node'; | |
import { Client } from '@opensearch-project/opensearch'; | |
// tslint:disable-next-line:no-var-requires | |
const createAwsOpensearchConnector = require('aws-opensearch-connector'); | |
export async function getEsClient(node: string = `https://${process.env.elasticsearch}`) { | |
const es = new Client({ | |
...createAwsOpensearchConnector({ | |
credentials: await defaultProvider()(), | |
region: process.env.AWS_REGION || 'eu-central-1', | |
getCredentials: (cb: () => void) => cb(), | |
}), | |
node, | |
}); | |
return es; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment