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
Parameter Type Required Example Description Action String Yes OpenSlsService The operation that you want to perform. Set the value to OpenSlsService. AccessKeyId String Yes test-key The AccessKey ID of your Alibaba Cloud account. For information about how to obtain an AccessKey pair, see AccessKey pair. Signature String Yes xxxxxx The signature string of the request. For more information, see Signature method. SignatureMethod String Yes HMAC-SHA1 The encryption method of the signature string. SignatureVersion String Yes 1.0 The version of the signature algorithm. SignatureNonce String Yes dt712rl9d A unique, random number that is used to prevent replay attacks. You must use different numbers for different requests. Timestamp String Yes 2018-01-01T12:00:00Z The 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). Version String Yes 2019-10-23 The version number of the API. The value must be in the YYYY-MM-DD format. Format String No JSON The format in which to return the response. Valid values: JSON and XML. Default value: XML.
Signature method
- Create a canonicalized query string.
- Create a string-to-sign.
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.
Parameter Type Example Description RequestId String 1CCC2B8E-4FF3-4755-A96C-8CE2E4BF27DF The ID of the request. Success Boolean true Indicates whether the request is successful. Valid values: true and false. - true: The request is successful.
- false: The request failed.
Code String 200 The returned status code. Message String You 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 code | Error code | Error message | Description |
---|---|---|---|
400 | PermissionDenied | No permission to open SLS service. | You are not authorized to activate Log Service. |
500 | GetSpecificationsFailed | Failed to get specifications of commodity. | The information about Log Service failed to be queried. |
500 | CreateOrderFailed | Failed to create an order. | The order failed to be created. |
For a list of error codes, see Error codes.