This topic describes the basic configurations of Log Service SDKs. You must specify the configurations when you use an SDK to access Log Service.

SDKs for all programming languages define a client class as an entry-point class. When you create a client class, you must complete the basic configurations.

The basic configurations are listed as follows:

  • Endpoint: the endpoint that is used by the client to access Log Service.
  • AccessKey pair: the AccessKey ID and AccessKey secret that is used by the client to access Log Service.

The following sections describe how to use endpoints and AccessKey pairs.

Endpoints

When you use an SDK to access a project in Log Service, you must specify the endpoint of the project to initialize the client. The endpoint is specified based on the region to which the project belongs, for example, China (Hangzhou) or China (Qingdao). The endpoint is the same as the endpoint that you use when you call an API operation. For more information, see Service endpoint.
  • When you select an endpoint for a client object, make sure that the region ID in the endpoint is the same as that of the project. Otherwise, you cannot access the project by using the SDK.
  • A client object is associated with an endpoint. To access projects in multiple regions, you must create multiple client objects. The endpoint of each project is configured for each client object.
  • All API endpoints support HTTPS and HTTP.
  • If you use an Elastic Compute Service (ECS) instance to access Log Service, you can configure an Alibaba Cloud internal endpoint to avoid public bandwidth overhead. For more information, see Service endpoint.

AccessKey pairs

All requests that are sent to Log Service must be authenticated. An AccessKey pair is used for the authentication. Each AccessKey pair consists of an AccessKey ID and AccessKey secret. When you create a client object, you must specify an AccessKey ID and AccessKey secret. Before you use an SDK, you must log on to the Alibaba Cloud Management Console, and go to the Security Management page to obtain or create an AccessKey pair.
Note
  • You can create multiple AccessKey pairs for your Alibaba Cloud account. When you create a client object, you can specify one of the AccessKey pairs. The AccessKey ID and AccessKey secret must be specified from the same AccessKey pair. Otherwise, the authentication will fail.
  • The specified AccessKey pair must be in the Enabled state. Otherwise, the requests will be rejected by Log Service. To view the status of the AccessKey pair, you can log on to the Alibaba Cloud Management Console.

Examples

You need to access a project in Log Service and you have an AccessKey pair that is in the Enabled state. The AccessKey pair is as follows:
AccessKeyId = "bq2sjzesjmo**************"
AccessKeySecret = "4fdO2fTDDnZPU/*************"
You can use the following script in different programming languages to create a client object:
  • Java
    String endpoint = "regionid.example.com";       // The endpoint of the project that you need to access. Specify the endpoint based on the access method and the region that the project resides.
    String accessKeyId = "bq2sjzesjmo**************";        // The AccessKey ID that you use to access the project.
    String accessKeySecret = "4fdO2fTDDnZPU/*************";// The AccessKey secret that you use to access the project.
    Client client = new Client(endpoint, accessKeyId, acccessKeySecret);
    //use client to operate log service project......
  • .NET(C#):
    String endpoint = "regionid.example.com"; // The endpoint of the project that you need to access. Specify the endpoint based on the access method and the region that the project resides.
    String accessKeyId = "bq2sjzesjmo**************";        // The AccessKey ID that you use to access the project.
    String accessKeySecret = "4fdO2fTDDnZPU/*************";// The AccessKey secret that you use to access the project.
    SLSClient client = new SLSClient(endpoint, accessKeyId, accessKeySecret);
    //use client to operate sls project......
  • PHP
    $endpoint = 'regionid.example.com'; // The endpoint of the project that you need to access. Specify the endpoint based on the access method and the region that the project resides.
    $accessKeyId = 'bq2sjzesjmo**************';  // The AccessKey ID that you use to access the project.
    $accessKey = '4fdO2fTDDnZPU/*************';// The AccessKey secret that you use to access the project.
    $client = new Aliyun_Sls_Client($endpoint, $accessKeyId, $accessKey);
    //use client to operate sls project......
  • Python
    # // The endpoint of the project that you need to access. Specify the endpoint based on the access method and the region that the project resides.
    endpoint = 'regionid.example.com'
    # The AccessKey ID that you use to access the project.
    accessKeyId = 'bq2sjzesjmo*************'
    # The AccessKey secret that you use to access the project.
    accessKey = '4fdO2fTDDnZPU/*************'  
    client = LogClient(endpoint, accessKeyId, accessKey)
    #use client to operate log project......