The Config class configures the Open Search TypeScript SDK client. It holds the endpoint, authentication credentials, and settings your application needs to call Open Search API operations.
Prerequisites
Before you begin, ensure that you have:
Node.js installed
An Alibaba Cloud account with Open Search enabled
A Resource Access Management (RAM) user with the required permissions (see Access authorization rules)
An AccessKey pair for the RAM user (see Create an AccessKey pair)
Use a RAM user's AccessKey pair instead of your Alibaba Cloud account's AccessKey pair. An account-level AccessKey pair grants access to all API operations — if it is leaked, all resources in your account are at risk. For information about creating a RAM user, see Create a RAM user. For information about granting the required permissions, see AliyunServiceRoleForOpenSearch.
Install dependencies
Install the required packages from npmjs.com.
Runtime dependencies:
npm install @alicloud/credentials @alicloud/opensearch-util @alicloud/tea-typescript @alicloud/tea-utilDevelopment dependencies:
npm install --save-dev typescript ts-nodeSet environment variables
Store your AccessKey pair as environment variables to avoid hardcoding credentials in your source code.
Linux and macOS Run the following commands. Replace
<access_key_id>and<access_key_secret>with the AccessKey ID and AccessKey secret of your RAM user.export ALIBABA_CLOUD_ACCESS_KEY_ID=<access_key_id> export ALIBABA_CLOUD_ACCESS_KEY_SECRET=<access_key_secret>Windows
Create an environment variable file, add
ALIBABA_CLOUD_ACCESS_KEY_IDandALIBABA_CLOUD_ACCESS_KEY_SECRETto the file, and set each to the corresponding value from your RAM user's AccessKey pair.Restart Windows for the changes to take effect.
Config class reference
The Config class extends $tea.Model and accepts the following fields in its constructor.
| Field | Type | Required | Description |
|---|---|---|---|
endpoint | string | No | The endpoint URL for the Open Search service in your region. |
protocol | string | No | The transfer protocol. |
type | string | No | The authentication type. |
securityToken | string | No | The Security Token Service (STS) token for temporary credentials. |
accessKeyId | string | No | The AccessKey ID. Read from the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable. |
accessKeySecret | string | No | The AccessKey secret. Read from the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable. |
userAgent | string | No | A custom user agent string appended to SDK requests. |
Config.ts
import * as $tea from '@alicloud/tea-typescript';
class Config extends $tea.Model {
endpoint?: string;
protocol?: string;
type?: string;
securityToken?: string;
accessKeyId?: string;
accessKeySecret?: string;
userAgent?: string;
static names(): { [key: string]: string } {
return {
endpoint: 'endpoint',
protocol: 'protocol',
type: 'type',
securityToken: 'securityToken',
// Read credentials from environment variables.
// Set ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET
// before running this code. See "Set environment variables" above.
accessKeyId: process.env.ALIBABA_CLOUD_ACCESS_KEY_ID,
accessKeySecret: process.env.ALIBABA_CLOUD_ACCESS_KEY_SECRET,
userAgent: 'userAgent',
};
}
static types(): { [key: string]: any } {
return {
endpoint: 'string',
protocol: 'string',
type: 'string',
securityToken: 'string',
accessKeyId: 'string',
accessKeySecret: 'string',
userAgent: 'string',
};
}
constructor(map?: { [key: string]: any }) {
super(map);
}
}
export default Config;What's next
Access authorization rules — grant the required permissions to your RAM user
AliyunServiceRoleForOpenSearch — understand the service-linked role used by Open Search