Activates Log Service. You must activate Log Service before you can use it to collect and manage logs.

Usage notes

An AccessKey pair is created and obtained. For more information, see AccessKey pair.

The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. Using these credentials to perform operations in Log Service is a high-risk operation. We recommend that you use a RAM user to call API operations or perform routine O&M. To create a RAM user, log on to the RAM console. Make sure that the RAM user is granted the permissions to manage Log Service resources. For more information, see Create a RAM user and authorize the RAM user to access Log Service.

Request syntax

POST https://sls.aliyuncs.com/
? AccessKeyId=yourAccessKeyId
&Action=OpenSlsService
&Format=Format
&SignatureMethod=HMAC-SHA1
&SignatureNonce=SignatureNonce
&SignatureVersion=SignatureVersion
&Timestamp=Timestamp
&Version=Version
&Signature=Signature

Request parameters

  • Request headers

    The OpenSlsService operation does not have operation-specific request headers.

  • Parameters
    ParameterTypeRequiredExampleDescription
    ActionStringYesOpenSlsServiceThe operation that you want to perform. Set the value to OpenSlsService.
    AccessKeyIdStringYestest-keyThe AccessKey ID of your Alibaba Cloud account. For information about how to obtain an AccessKey pair, see AccessKey pair.
    SignatureStringYesxxxxxxThe signature string of the request. For more information, see Signature method.
    SignatureMethodStringYesHMAC-SHA1The encryption method of the signature string.
    SignatureVersionStringYes1.0The version of the signature algorithm.
    SignatureNonceStringYesdt712rl9dA unique, random number that is used to prevent replay attacks. You must use different numbers for different requests.
    TimestampStringYes2018-01-01T12:00:00ZThe timestamp of the request. Specify the time in the ISO 8601 standard in the yyyy-MM-ddTHH:mm:ssZ format. The time must be in UTC. For example, 2018-01-01T12:00:00Z indicates 20:00:00 on January 1, 2018 (UTC+8).
    VersionStringYes2019-10-23The version number of the API. The value must be in the YYYY-MM-DD format.
    FormatStringNoJSONThe format in which to return the response. Valid values: JSON and XML. Default value: XML.

Signature method

  1. Create a canonicalized query string.
    1. Create a canonicalized query string by arranging the request parameters in alphabetical order. These parameters include all common and operation-specific parameters except Signature.
    2. Encode the parameters in UTF-8. For more information, see RFC 3986.
      • Uppercase letters, lowercase letters, digits, and specific special characters such as hyphens (-), underscores (_), periods (.), and tildes (~) do not need to be encoded.
      • Other characters must be percent encoded in the %XY format. XY represents the ASCII code of the characters in hexadecimal notation. For example, double quotation marks (") are encoded as %22.
      • Use an equal sign (=) to concatenate each encoded request parameter and its value.
      • Use an ampersand (&) to concatenate encoded request parameters in alphabetical order. These parameters include all common and operation-specific parameters except Signature.
    3. Obtain the canonicalized query string.
  2. Create a string-to-sign.
    1. Create StringToSign.
      StringToSign=
        HTTPMethod + "&" +                      //HTTPMethod: HTTP method used to send the request, such as GET. 
        percentEncode("/") + "&" +              //percentEncode("/"): Encode backslash (/) as %2F. 
        percentEncode(CanonicalizedQueryString) //Encode the canonicalized query string created in Step 1. 
    2. Calculate the HMAC value of the string-to-sign as defined in RFC 2104. Use the SHA1 algorithm to calculate the HMAC value of the StringToSign. The AccessKey secret is used as the key for the HMAC calculation.
      Signature = Base64( HMAC-SHA1( AccessKeySecret + "&", UTF-8-Encoding-Of(StringToSign) ) )
    3. Encode the Signature parameter based on the RFC 3986 specification and add the encoded signature to the canonicalized query string.

The following sample code shows how to use Python to call the OpenSlsService operation:

import base64
import datetime
import hmac
import random
from hashlib import sha1
from urllib import parse

import pytz

url = 'https://sls.aliyuncs.com/?'
accessKeyId = 'test-key'
accessKeySecret = 'test-secret'

params = {
    'AccessKeyId': accessKeyId,
    'Action': 'OpenSlsService',
    'Format': 'JSON',
    'Version': '2019-10-23',
    'SignatureMethod': 'HMAC-SHA1',
    'SignatureNonce': str(int(random.random() * 1000000)),
    'SignatureVersion': '1.0',
    'Timestamp': parse.quote(
        datetime.datetime.now(pytz.utc).strftime('%Y-%m-%dT%H:%M:%SZ')
    )
}


def create_url():
    kvs = sorted(params.items(), key=lambda x: x[0])
    paramStr = '&'.join([k + '=' + v for k, v in kvs])
    sigStr = 'GET&%2F&' + parse.quote(paramStr, safe='')
    hashed = hmac.new((accessKeySecret + '&').encode(), sigStr.encode(), sha1)
    signature = base64.encodebytes(
        hashed.digest()).decode('utf-8').rstrip('\n')
    return url + paramStr + '&Signature=' + signature

print(create_url())

Response elements

  • Response headers

    The OpenSlsService operation does not have operation-specific response headers.

  • Response elements

    If the HTTP status code 200 is returned, the request is successful.

    ParameterTypeExampleDescription
    RequestIdString1CCC2B8E-4FF3-4755-A96C-8CE2E4BF27DFThe ID of the request.
    SuccessBooleantrueIndicates whether the request is successful. Valid values: true and false.
    • true: The request is successful.
    • false: The request failed.
    CodeString200The returned status code.
    MessageStringYou have activated Log Service. You can go to the Log Service console to manage logs.The description of the response returned.

Examples

  • Sample requests
    https://sls.aliyuncs.com/
    ? AccessKeyId=test-key
    &Action=OpenSlsService
    &Format=JSON
    &SignatureMethod=HMAC-SHA1
    &SignatureNonce=222856
    &SignatureVersion=1.0
    &Timestamp=2020-09-15T13%3A01%3A26Z
    &Version=2019-10-23
    &Signature=xxxxxxx
  • Sample success responses
    {
      "RequestId": "1CCC2B8E-4FF3-4755-A96C-8CE2E4BF27DF",
      "Message": "You have activated Log Service. You can go to the Log Service console to manage logs.",
      "Code": "200",
      "Success": true
    }

Error codes

HTTP status codeError codeError messageDescription
400PermissionDeniedNo permission to open SLS service.You are not authorized to activate Log Service.
500GetSpecificationsFailedFailed to get specifications of commodity.The information about Log Service failed to be queried.
500CreateOrderFailedFailed to create an order.The order failed to be created.

For a list of error codes, see Error codes.