Config holds the parameters required to authenticate and connect to the OpenSearch API. Pass a Config instance to the client constructor to initialize a connection.
Parameters
| Parameter | Type | Description |
|---|---|---|
Endpoint | string | The OpenSearch API endpoint. Omit the http:// or https:// prefix — the protocol is set separately by the Protocol parameter. |
Protocol | string | The request protocol. Valid values: HTTP, HTTPS. |
Type | string | The authentication method. Valid values: access_key (Alibaba Cloud account or RAM user) and sts (Security Token Service). |
AccessKeyId | string | The AccessKey ID used to access OpenSearch. |
AccessKeySecret | string | The AccessKey secret used to access OpenSearch. |
SecurityToken | string | The security token for Security Token Service (STS) authentication. Required only when Type is set to sts. To get a token, call the AssumeRole operation of Alibaba Cloud Resource Access Management (RAM). |
UserAgent | string | Custom user agent information. Leave blank in most cases. |
To create an AccessKey pair, go to the AccessKey Pair page.
Sample code
The following example defines a Config class that inherits from TeaModel:
using System;
using System.Collections.Generic;
using System.IO;
using Tea;
public class Config : TeaModel
{
[NameInMap("endpoint")]
[Validation(Required = false)]
public string Endpoint { get; set; }
[NameInMap("protocol")]
[Validation(Required = false)]
public string Protocol { get; set; }
[NameInMap("type")]
[Validation(Required = false)]
public string Type { get; set; }
[NameInMap("securityToken")]
[Validation(Required = false)]
public string SecurityToken { get; set; }
[NameInMap("accessKeyId")]
[Validation(Required = false)]
public string AccessKeyId { get; set; }
[NameInMap("accessKeySecret")]
[Validation(Required = false)]
public string AccessKeySecret { get; set; }
[NameInMap("userAgent")]
[Validation(Required = false)]
public string UserAgent { get; set; }
}Authentication methods
AccessKey authentication — use for Alibaba Cloud accounts and RAM users:
var config = new Config
{
Endpoint = "<your-endpoint>",
Protocol = "HTTPS",
Type = "access_key",
AccessKeyId = Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_ID"),
AccessKeySecret = Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_SECRET"),
};STS authentication — use for temporary credentials issued via RAM's AssumeRole operation:
var config = new Config
{
Endpoint = "<your-endpoint>",
Protocol = "HTTPS",
Type = "sts",
AccessKeyId = Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_ID"),
AccessKeySecret = Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_SECRET"),
SecurityToken = Environment.GetEnvironmentVariable("ALIBABA_CLOUD_SECURITY_TOKEN"),
};Replace <your-endpoint> with your OpenSearch API endpoint, without the protocol prefix.
该文章对您有帮助吗?