Update current Lambda to support both Classic and Retail

This commit is contained in:
Emily Doherty 2023-09-24 00:27:49 -07:00
parent 1ff0631915
commit b2a49dd712

View File

@ -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)