Skip to content
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

support AWS SDK v3 #7

Merged
merged 1 commit into from
Jul 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc → .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ env:
es6: true

parserOptions:
ecmaVersion: 8
ecmaVersion: 2021
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

52 changes: 49 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ A tiny [Amazon Signature Version 4](https://www.npmjs.com/package/aws4) connecti

Supports AWS SDK global or specific configuration instances (AWS.Config), including asyncronous credentials from IAM roles and credential refreshing.

## Installation

```bash
npm install --save aws-opensearch-connector
```

## Example usage

### Using global configuration
Expand All @@ -17,8 +23,8 @@ const createAwsOpensearchConnector = require('aws-opensearch-connector')

// (Optional) load profile credentials from file
AWS.config.update({
profile: 'my-profile'
})
profile: "my-profile",
});

const client = new Client({
...createAwsOpensearchConnector(AWS.config),
Expand All @@ -42,7 +48,47 @@ const client = new Client({
...createAwsOpensearchConnector(awsConfig),
node: 'https://my-opensearch-cluster.us-east-1.es.amazonaws.com'
})
````

```

### Using aws-sdk v3

```javascript
const { STSClient, AssumeRoleCommand } = require("@aws-sdk/client-sts");
const { Client } = require('@opensearch-project/opensearch')
const createAwsOpensearchConnector = require("./src/index.js");

async function ping() {
const creds = await assumeRole(
"arn:aws:iam::0123456789012:role/Administrator",
"us-east-1"
);
const client = new Client({
...createAwsOpensearchConnector({
region: "us-east-1",
credentials: creds,
}),
node: "https://my-opensearch-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

Expand Down
11 changes: 11 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Connection, Transport } from '@opensearch-project/opensearch';
import AWS from 'aws-sdk';

export type Connector = {
Connection: typeof Connection;
Transport: typeof Transport;
};

export const ConnectorFactory: (awsConfig: AWS.Config) => Connector;

export default ConnectorFactory;
Loading