commit b2a49dd712c5a05d5426db04807cf38c50eb073e
parent 1ff0631915563c77c1ffd2ab03e095a763f47a22
Author: Emily Doherty <git@emily.sh>
Date: Sun, 24 Sep 2023 00:27:49 -0700
Update current Lambda to support both Classic and Retail
Diffstat:
1 file changed, 16 insertions(+), 3 deletions(-)
diff --git a/wow-token-current.py b/wow-token-current.py
@@ -30,7 +30,8 @@ else:
local_region = 'eu-north-1'
dynamodb_client = boto3.resource('dynamodb', region_name=local_region)
-table = dynamodb_client.Table('wow-token-price')
+retail_table = dynamodb_client.Table('wow-token-price')
+classic_table = dynamodb_client.Table('wow-token-classic-price')
regions = ['us', 'eu', 'tw', 'kr']
regional_data = {
@@ -41,7 +42,12 @@ regional_data = {
}
-def token_data():
+def token_data(version: str) -> dict:
+ if version == 'retail':
+ table = retail_table
+ else:
+ table = classic_table
+
items = table.scan()['Items']
data = {
'current_time': datetime.datetime.utcfromtimestamp(int(items[0]['current_time'])).replace(
@@ -54,7 +60,14 @@ def token_data():
def lambda_handler(event, context):
- data = token_data()
+ uri = event['Records'][0]['cf']['request']['uri']
+ print(f"URI:\t${uri}")
+ split_uri = uri.split('/')
+ if split_uri[-3] == 'classic':
+ version = 'classic'
+ else:
+ version = 'retail'
+ data = token_data(version)
response = {'status': '200', 'statusDescription': 'OK', 'headers': {}}
response['headers']['content-type'] = [{'key': 'Content-Type', 'value': 'application/json'}]
response['body'] = json.dumps(data)