Mobile apps are commonly used to upload data due to the fast development of the mobile Internet. If logs can be uploaded from mobile apps to Log Service instead of being transferred by app servers, you can focus on the development of your business logic.
Background information
When you write logs to Log Service in normal mode, you must use the AccessKey pair of your Alibaba Cloud account for authentication and anti-tamper protection. If a mobile app accesses Log Service in this mode, you must save your AccessKey pair on a mobile client. This increases the risk of data leaks if the AccessKey pair is exposed. If your AccessKey pair is exposed, you must upgrade the mobile app and change the AccessKey pair. This process is complex and costly. To upload logs from mobile clients to Log Service, you can also use app servers to transfer the logs. If the number of mobile apps is large, the app servers must meet high performance requirements to carry all data from mobile clients.
To prevent the preceding issues, Log Service provides a more secure and convenient solution to collect logs from mobile apps based on Resource Access Management (RAM). You can use RAM to directly transfer data. In this mode, you do not need to save your AccessKey pair on a mobile client. This prevents your AccessKey pair from being exposed. You can use a temporary token to increase data security. The temporary token has a lifecycle. You can configure access permission policies for the temporary token. For example, you can reject access requests from specified CIDR blocks.
You can create a RAM role of Log Service and configure a mobile app as a RAM user to assume this role. This way, you can build a data transfer service for the mobile app based on Log Service within 30 minutes. The direct data transfer service allows mobile apps to directly access Log Service, and only the control flow is sent to app servers.
Benefits
- Higher access security: Flexible and temporary permission assignment and authentication are supported.
- Lower cost: Fewer servers are required. Mobile apps are directly connected to Alibaba Cloud and only the control flow is sent to app servers.
- Higher concurrency: A large number of users can use the service at the same time. Higher upload bandwidth and download bandwidth are provided by Log Service.
- Auto scaling: Log Service provides unlimited storage space.

Node | Description |
---|---|
Android or iOS mobile app | The app on the mobile phones of users. Logs are generated by the app. |
SLS | Log Service. Log Service stores log data that is uploaded from the app. |
RAM/STS | RAM. This service allows you to manage user identities and resource access permissions. You can use RAM to generate temporary upload credentials. |
App server | The backend service that is developed for the Android or iOS app. The app server manages tokens that are used by the app to upload and download logs. The app server also manages the metadata that is uploaded by users to the app. |
Configuration process
- An Android or iOS app requests a temporary access credential from your app server.
To prevent data leaks, the Android or iOS app does not store the AccessKey ID or AccessKey secret. The Android or iOS app must request a temporary upload credential (a token) from your app server. The token is valid only for a specific period of time. For example, if the validity period of a token is set to 30 minutes, the Android or iOS app can use this token to access Log Service within 30 minutes. The validity period of a token can be specified by the app server. However, the app must request a new token after 30 minutes.Notice Each time the Android or iOS app obtains a token from the app server, the app server caches the token based on the validity period. We recommend that the app server sends the cached token as a response to each client request. After the cached token expires, the app server requests a new token.
- The app server verifies the preceding request and returns a token to the Android or iOS app.
- After the mobile app obtains the token, the mobile app can access Log Service.
This topic describes how to use an app server to request a token from RAM, and how to obtain the token for an Android or iOS app.
Procedure
Download the source code
Sample code of the app server: PHP, Java, Ruby, and Node.js.