Skip to content

Instantly share code, notes, and snippets.

@gbvanrenswoude
Created December 15, 2022 16:38
Show Gist options
  • Save gbvanrenswoude/61e8142dcd30fe6de040307b5524ef22 to your computer and use it in GitHub Desktop.
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
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