You can use the data transformation feature of Log Service to obtain the IP2Location library from Object Storage Service (OSS) and use the library to identify the city, state, and country to which an IP address belongs.
- The IP2Location library is downloaded from the IPIP.NET website and uploaded to OSS.
For more information, see Upload objects.
We recommend that you use an AccessKey pair that has write-only permissions on OSS to upload the library.
- Raw log entry:
- Transformation rule:
e_set("geo", geo_parse(v("ip"), ip_db=res_oss_file(endpoint='http://oss-cn-hangzhou.aliyuncs.com', ak_id=res_local("AK_ID"), ak_key=res_local("AK_KEY"), bucket='test', file='your ip2location bin file', format='binary', change_detect_interval=20), provider="ip2location")) e_json("geo")The following table describes the fields in the res_oss_file function.
Field Description endpoint The endpoint of OSS. For more information, see Regions and endpoints. ak_id The AccessKey ID that has read permissions on OSS.For security concerns, we recommend that you set the value to res_local("AK_ID") in the Advanced Parameter Settings field. For information about how to set the Advanced Parameter Settings field, see Create a data transformation rule. ak_key The AccessKey secret that has read permissions on OSS.
For security concerns, we recommend that you set the value to res_local("AK_KEY") in the Advanced Parameter Settings field.
bucket The OSS bucket used to store the IP address library. file The name of the IP address library that you have uploaded. format The format of the data obtained from the IP address library. Set the value to binary.
ip: 18.104.22.168 city: Dearborn province: Michigan country: United States