Configuration

Last Updated: Jun 17, 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 access key (consisting of an access key ID and access key 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.

  1. 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.
  2. 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.
  3. Currently, the endpoints of all APIs support only HTTP.
  4. 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.

Access key:

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

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

Example:

Access a project in the “China East 1 (Hangzhou)” region with an “active” access key. The access key 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"; //Access key ID of the access key.
  3. String accessKeySecret = "4fdO2fTDDnZPU/L7CHNdemB2Nsk=";//Access key secret of the access key.
  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"; //Access key ID of the access key.
  3. String accessKeySecret = "4fdO2fTDDnZPU/L7CHNdemB2Nsk=";//Access key secret of the access key.
  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'; //Access key ID of the access key.
  3. $accessKey = '4fdO2fTDDnZPU/L7CHNdemB2Nsk=';//Access key secret of the access key.
  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. # Access key ID of the access key.
  4. accessKeyId = 'bq2sjzesjmo86kq35behupbq'
  5. # Access key secret of the access key.
  6. accessKey = '4fdO2fTDDnZPU/L7CHNdemB2Nsk='
  7. client = LogClient(endpoint, accessKeyId, accessKey)
  8. #use client to operate log project......
Thank you! We've received your feedback.