Update current Lambda to support both Classic and Retail
This commit is contained in:
parent
1ff0631915
commit
b2a49dd712
@ -30,7 +30,8 @@ else:
|
|||||||
local_region = 'eu-north-1'
|
local_region = 'eu-north-1'
|
||||||
|
|
||||||
dynamodb_client = boto3.resource('dynamodb', region_name=local_region)
|
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']
|
regions = ['us', 'eu', 'tw', 'kr']
|
||||||
regional_data = {
|
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']
|
items = table.scan()['Items']
|
||||||
data = {
|
data = {
|
||||||
'current_time': datetime.datetime.utcfromtimestamp(int(items[0]['current_time'])).replace(
|
'current_time': datetime.datetime.utcfromtimestamp(int(items[0]['current_time'])).replace(
|
||||||
@ -54,7 +60,14 @@ def token_data():
|
|||||||
|
|
||||||
|
|
||||||
def lambda_handler(event, context):
|
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 = {'status': '200', 'statusDescription': 'OK', 'headers': {}}
|
||||||
response['headers']['content-type'] = [{'key': 'Content-Type', 'value': 'application/json'}]
|
response['headers']['content-type'] = [{'key': 'Content-Type', 'value': 'application/json'}]
|
||||||
response['body'] = json.dumps(data)
|
response['body'] = json.dumps(data)
|
||||||
|
Loading…
Reference in New Issue
Block a user