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

Ignore egress requests updated more than 90 days ago #12

Merged
merged 2 commits into from
Mar 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions egress_backend/lambda/egress_api/list_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
# agreement between Customer and Amazon Web Services, Inc.

import os
from datetime import datetime

import boto3
from aws_lambda_powertools import Logger, Tracer

MAX_REQUEST_AGE_DAYS = 90

tracer = Tracer(service="ListRequestsAPI")
logger = Logger(service="ListRequestsAPI")

Expand All @@ -18,9 +21,19 @@
def list_requests():
logger.debug("List Requests API invoked")

now = datetime.now()

def is_recent(item):
updated_dt = datetime.strptime(item["updated_dt"], "%Y-%m-%dT%H:%M:%S.%fZ")
return (now - updated_dt).days < MAX_REQUEST_AGE_DAYS

ddb_table = ddb.Table(table)

response = ddb_table.scan()
data = [item for item in response["Items"] if is_recent(item)]
while response.get("LastEvaluatedKey"):
response = ddb_table.scan(ExclusiveStartKey=response["LastEvaluatedKey"])
data.extend([item for item in response["Items"] if is_recent(item)])

logger.debug("Succesful database scan of all egress requests")
return response["Items"]
logger.debug("Successful database scan of all egress requests")
return data
Loading