All Products
Search
Document Center

Simple Log Service:Configurations

Last Updated:Oct 26, 2023

You must configure basic settings when you use Simple Log Service SDK to access Simple Log Service. This topic describes the basic settings of the SDK.

Simple Log Service SDK in all programming languages defines a client class as an entry-point class. When you create a client class, you must configure basic settings for the SDK.

Basic settings:

  • Endpoint: the endpoint that is used by a client to access Simple Log Service.

  • AccessKey pair: the credential that is used by a client to access Simple Log Service. An AccessKey pair consists of an AccessKey ID and an AccessKey secret.

The following sections describe how to configure an endpoint and an AccessKey pair.

Endpoint

When you use Simple Log Service SDK to access a project of Simple Log Service, you must specify the endpoint of the project to create your client. The endpoint varies based on the region of the project. Examples of regions are China (Hangzhou) and China (Qingdao). The endpoint is the same as the endpoint that you use when you call an API operation. For more information, see Endpoints.

  • When you specify an endpoint to create a client, make sure that the region of the endpoint is the same as the region of the project that you want to access. Otherwise, you cannot access the project by using the SDK.

  • You can specify an endpoint for a client only when you create the client. If you want to access a project in a different region, you must specify a different endpoint to create another client.

  • All API endpoints support HTTPS and HTTP.

  • If you use Simple Log Service SDK on an Elastic Compute Service (ECS) instance to access Simple Log Service, you can specify an Alibaba Cloud internal endpoint to avoid public bandwidth fees. For more information about internal endpoints, see Endpoints.

AccessKey pair

Authentication is required for all requests to access Simple Log Service. An AccessKey pair consists of an AccessKey ID and an AccessKey secret and is a critical factor for authentication. When you create a client, you must specify an AccessKey pair. Before you use Simple Log Service SDK, you must obtain or create an AccessKey pair on the AccessKey Management page of the Alibaba Cloud Management Console and configure the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables. For more information, see Configure environment variables.

Important
  • You can create multiple AccessKey pairs for your Alibaba Cloud account. When you create a client, you can specify one of the AccessKey pairs. The AccessKey ID and AccessKey secret must pair each other. Otherwise, the authentication fails.

  • The AccessKey pair that you specify must be enabled. Otherwise, Simple Log Service rejects the requests that you send. You can view the status of an AccessKey pair in the Alibaba Cloud Management Console.

  • The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. We recommend that you use the AccessKey pair of a Resource Access Management (RAM) user to call API operations or perform routine O&M.

  • We recommend that you do not save the AccessKey ID or AccessKey secret in your project code. Otherwise, the AccessKey pair may be leaked, and the security of all resources within your account may be compromised.

Examples

You can use the following scripts in different programming languages to create a client:

  • Java

    // Specify the endpoint based on the region of the project that you want to access. 
    String endpoint = "Region ID.example.com";
    // Configure environment variables. In this example, the AccessKey ID and AccessKey secret are obtained from environment variables. 
    String accessKeyId =  System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");        
    String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
    Client client = new Client(endpoint, accessKeyId, accessKeySecret);
    //use client to operate log service project......

    For more information, see Get started with Simple Log Service SDK for Java.

  • .NET (C#)

    // Specify the endpoint based on the region of the project that you want to access. 
    String endpoint = "Region ID.example.com";  
    // Configure environment variables. In this example, the AccessKey ID and AccessKey secret are obtained from environment variables. 
    String accessKeyId = Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_ID");   
    String accessKeySecret = Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
    SLSClient client = new SLSClient(endpoint, accessKeyId, accessKeySecret);
    //use client to operate sls project......

    For more information, see Get started with Simple Log Service SDK for .NET.

  • PHP

    // Specify the endpoint based on the region of the project that you want to access. 
    $endpoint = 'Region ID.example.com'; 
    // Configure environment variables. In this example, the AccessKey ID and AccessKey secret are obtained from environment variables. 
    $accessKeyId = getenv('ALIBABA_CLOUD_ACCESS_KEY_ID');        
    $accessKey = getenv('ALIBABA_CLOUD_ACCESS_KEY_SECRET'); 
    $client = new Aliyun_Sls_Client($endpoint, $accessKeyId, $accessKey);
    //use client to operate sls project......

    For more information, see Get started with Simple Log Service SDK for PHP.

  • Python

    # Specify the endpoint based on the region of the project that you want to access. 
    endpoint = 'Region ID.example.com'
    # Configure environment variables. In this example, the AccessKey ID and AccessKey secret are obtained from environment variables. 
    accessKeyId = os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_ID', '')
    accessKey = os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_SECRET', '')
    client = LogClient(endpoint, accessKeyId, accessKey)
    #use client to operate log project......

    For more information, see Get started with Simple Log Service SDK for Python.