From b9b44a5e20a630dfb5229b0254accebcacfea5bf Mon Sep 17 00:00:00 2001 From: Justin Smallwood Date: Thu, 11 Jul 2024 11:48:55 +1000 Subject: [PATCH] Move boto3 calls within function. --- src/lambda_function.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/lambda_function.py b/src/lambda_function.py index 99992db..372a74e 100644 --- a/src/lambda_function.py +++ b/src/lambda_function.py @@ -14,8 +14,7 @@ load_dotenv() -dynamodb = boto3.resource("dynamodb") -table = dynamodb.Table("UVIndexTable") + def handler(event, context): @@ -56,6 +55,9 @@ def get_previous_uv(uv: float) -> float: If no previous value was logged for today - defaults to returning zero. """ + dynamodb = boto3.resource("dynamodb") + table = dynamodb.Table("UVIndexTable") + date_today = datetime.now(tz=timezone("Australia/Sydney")).strftime("%Y-%m-%d") response = table.query(KeyConditionExpression=Key("date").eq(date_today))