Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paginate list_requests DynamoDb.scan #11

Merged
merged 1 commit into from
Mar 20, 2024
Merged

Paginate list_requests DynamoDb.scan #11

merged 1 commit into from
Mar 20, 2024

Conversation

manics
Copy link
Member

@manics manics commented Mar 20, 2024

Description

DynamoDB has a 1MB limit on responses. Pagination is needed for scanning larger tables.
https://stackoverflow.com/questions/36780856/complete-scan-of-dynamodb-with-boto3/38619425#38619425


Declaration : By submitting this pull request, I confirm that my
contribution is made under the terms of the Apache-2.0 license

@manics
Copy link
Member Author

manics commented Mar 20, 2024

Tested with this temporary local change to check the pagination logic:

diff --git a/egress_backend/lambda/egress_api/list_requests.py b/egress_backend/lambda/egress_api/list_requests.py
index c4b3250..d3f8d43 100644
--- a/egress_backend/lambda/egress_api/list_requests.py
+++ b/egress_backend/lambda/egress_api/list_requests.py
@@ -20,10 +20,12 @@ def list_requests():
 
     ddb_table = ddb.Table(table)
 
-    response = ddb_table.scan()
+    response = ddb_table.scan(Limit=10)
+    print(response)
     data = response["Items"]
     while response.get("LastEvaluatedKey"):
         response = ddb_table.scan(ExclusiveStartKey=response["LastEvaluatedKey"])
+        print(response)
         data.extend(response["Items"])
 
     logger.debug("Successful database scan of all egress requests")

@manics manics merged commit b5c43ca into main Mar 20, 2024
2 checks passed
@manics manics deleted the list-pagination branch March 20, 2024 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants