Use the following example IAM policy to provide these restrictions:
Any IAM principal created by IAM admins can have full access to AWS resources. The full access to AWS resources depends upon the identity-based policies because permissions boundaries don’t provide permissions on their own.
The policy restricts IAM principals from accessing AWS Billing and Cost Management related services.
IAM principals can’t alter the permissions boundary to allow their own permissions to access restricted services.
IAM admins can’t create IAM principals with more privileges than they already have.
The IAM principals created by IAM admins can’t create IAM principals with more permissions than IAM admins.
Save this policy as a managed policy named ScopePermissions. Replace YourAccount_ID with your account ID.
In each request, clients pass a cursor and a page_size
The cursor refers to a specific unique value in the database.
If the cursor is not given, the server fetches from the first record.
SELECT*FROM users
WHERE id <=%cursorORDERBY id DESC
LIMIT %<limit +1>
The server fetches (limit + 1) records whose ID is smaller than the cursor value.
Note that the limit is equal to the given page size plus one.
If the number of records returned is less than the LIMIT, it implies that we are on the last page.
The extra record is not returned to the client. The ID of the extra record is passed back to the client as the next_cursor.
response:{"users":[...],"next_cursor":"12335", # the user id of the extra result
}
Pros
Stable pagination window
Since we are fetching from a stable reference point, the addition or deletion of record will not affect the pagination window.
Scale well with large datasets
The cursor is unique and indexed.
The database jumps directly to the record without iterating through the unwanted data. Hence, making it more efficient.
Cons
The cursor pagination doesn’t allow clients to jump to a specific page.
The cursor must come from a unique and sequential column (E.g. timestamp). Otherwise, some data will be skipped.
Limited sort features. If the requirement is to sort based on a non-unique column (E.g. first name), it will be challenging to implement using cursor pagination. Concatenating multiple columns to get a unique key leads to slower time complexity.
Keyset pagination
Offset and Limit Pagination
Offset Pagination
The offset pagination leverages the OFFSET and LIMIT commands in SQL to paginate data.
Implementation
Paginate using the OFFSET & LIMIT command in SQL
Said we are implementing an API to get a list of user information.
API: GET /api/user/list
request:{
page_size:10,
page_number:3}
In each request, clients pass a page_size (offset) and a page_number (limit).
Page size indicates the number of data to be returned.
Page number indicates the current requesting page.
SELECTCOUNT(*) AS total FROM user_tab;
The server first queries the total number of records from the user table.
This allows the clients to grasp the number of total pages.
SELECT*FROM user_tab
ORDERBY id DESC
LIMIT 10OFFSET20;
The server utilises the offset and limit commands to retrieve ten records from the table.
Since the given page_number is 3, the offset = 10 * 2 = 20.