Configuration

Last Updated: Nov 29, 2017

Like using APIs to interact with the Log Service, you need to specify basic configurations when using SDKs. Currently, the SDKs in all languages define a Client class as the portal class. Basic configurations are specified during the portal construction process. The basic configurations include:

  • Endpoint: portal through which the client accesses the Log Service
  • Alibaba Cloud AccessKey (consisting of an AccessKey ID and AccessKey secret): used by the client to access the Log Service

The usage instructions of the two configuration items are described below.

Endpoint:

When using an SDK, specify the region of the Log Service project you want to access (for example, “China East 1 (Hangzhou)” and “China North 1 (Qingdao)”). Then select the matched Log Service endpoint for client initialization. The endpoint is defined in the same way as the endpoints of APIs.

  • When you select an endpoint for the client, ensure that the region of the project you want to access is the same as the region of the selected endpoint. If they are different, the SDK cannot access the project.
  • Because the endpoint can only be specified during the construction of a client instance, if you need to access a project in a different region, you must use a different endpoint to construct a different client instance.
  • Currently, the endpoints of all APIs support only HTTP.
  • If you apply an SDK on Alibaba Cloud ECS VMs, you can use an intranet endpoint to avoid public bandwidth overhead. For details, refer to Endpoint.

AccessKey:

As described in the AccessKey section, all requests that interact with the Log Service must undergo security verification. An AccessKey is a critical factor in request security verification and is created by pairing an AccessKey ID and AccessKey secret. During client construction, the AccessKey ID and AccessKey secret must be specified to create an AccessKey. Before using an SDK, log on to the Alibaba Cloud Console and obtain or create an applicable AccessKey on the key management page. Note the following points during client construction:

  • If you have multiple AccessKey under your Alibaba Cloud account, ensure that the AccessKey ID and AccessKey secret specified during client construction are in pair; otherwise, the created AccessKey cannot pass the security verification required by the Log Service.
  • The specified AccessKey must be “active”; otherwise, the request is denied by the Log Service. You can log on to the Alibaba Cloud Console to view the AccessKey status on the key management page.

Example:

Access a project in the “China East 1 (Hangzhou)” region with an “active” AccessKey. The AccessKey is as follows:

  1. AccessKeyId = "bq2sjzesjmo86kq35behupbq"
  2. AccessKeySecret = "4fdO2fTDDnZPU/L7CHNdemB2Nsk="

The corresponding client instance is instantiated as follows:

Java:
  1. String endpoint = "cn-hangzhou.sls.aliyuncs.com"; //Log Service endpoint in the "China East 1 (Hangzhou)" region.
  2. String accessKeyId = "bq2sjzesjmo86kq35behupbq"; //AccessKey ID of the AccessKey.
  3. String accessKeySecret = "4fdO2fTDDnZPU/L7CHNdemB2Nsk=";//AccessKey secret of the AccessKey.
  4. Client client = new Client(endpoint, accessKeyId, acccessKeySecret);
  5. //use client to operate log service project......
.NET(C#):
  1. String endpoint = "cn-hangzhou.sls.aliyuncs.com"; //Log Service endpoint in the "China East 1 (Hangzhou)" region.
  2. String accessKeyId = "bq2sjzesjmo86kq35behupbq"; //AccessKey ID of the AccessKey.
  3. String accessKeySecret = "4fdO2fTDDnZPU/L7CHNdemB2Nsk=";//AccessKey secret of the AccessKey.
  4. SLSClient client = new SLSClient(endpoint, accessKeyId, accessKeySecret);
  5. //use client to operate sls project......
PHP:
  1. $endpoint = 'cn-hangzhou.sls.aliyuncs.com'; //Log Service endpoint in the "China East 1 (Hangzhou)" region.
  2. $accessKeyId = 'bq2sjzesjmo86kq35behupbq'; //AccessKey ID of the AccessKey.
  3. $accessKey = '4fdO2fTDDnZPU/L7CHNdemB2Nsk=';//AccessKey secret of the AccessKey.
  4. $client = new Aliyun_Sls_Client($endpoint, $accessKeyId, $accessKey);
  5. //use client to operate sls project......
Python:
  1. # Log Service endpoint in the "China East 1 (Hangzhou)" region.
  2. endpoint = 'cn-hangzhou.sls.aliyuncs.com'
  3. # AccessKey ID of the AccessKey.
  4. accessKeyId = 'bq2sjzesjmo86kq35behupbq'
  5. # AccessKey secret of the AccessKey.
  6. accessKey = '4fdO2fTDDnZPU/L7CHNdemB2Nsk='
  7. client = LogClient(endpoint, accessKeyId, accessKey)
  8. #use client to operate log project......
Thank you! We've received your feedback.