-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from blue-shoes/dev
v2.0 Release
- Loading branch information
Showing
18 changed files
with
1,052 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
*/ | ||
deployment.zip |
88 changes: 88 additions & 0 deletions
88
src/lambda_functions/otto-bot-player-load/lambda_function.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
from urllib import parse as urlparse | ||
import base64 | ||
import json | ||
import os | ||
import requests | ||
import boto3 | ||
|
||
client = boto3.client('lambda') | ||
|
||
def lambda_handler(event, context): | ||
|
||
print(event) | ||
|
||
msg_map = dict(urlparse.parse_qsl(base64.b64decode(str(event['body'])).decode('ascii'))) | ||
|
||
print(event['requestContext']) | ||
|
||
msg_map['stage'] = event['requestContext']['stage'] | ||
|
||
print(msg_map) | ||
|
||
payload_json = msg_map.get('payload', None) | ||
if payload_json: | ||
payload = json.loads(msg_map['payload']) | ||
search_value = payload.get('value', None) | ||
if search_value: | ||
search_parameters = { | ||
"search_name" : search_value, | ||
"stage" : msg_map['stage'] | ||
} | ||
|
||
search_version = os.environ[f'{msg_map["stage"]}_search_version'] | ||
|
||
response = client.invoke( | ||
FunctionName = os.environ['player_search_lambda_arn'], | ||
InvocationType = 'RequestResponse', | ||
Payload = json.dumps(search_parameters), | ||
Qualifier = search_version | ||
) | ||
|
||
lambda_response = json.load(response['Payload']) | ||
|
||
if 'body' in lambda_response: | ||
player_list = json.loads(lambda_response['body']) | ||
options = list() | ||
for player_dict in player_list: | ||
name = f"{', '.join([player_dict['name'], player_dict['positions'], player_dict.get('org', 'FA')])}" | ||
value = int(player_dict['_id']) | ||
|
||
options.append( | ||
{ | ||
'text': { | ||
'type': 'plain_text', | ||
'text': name | ||
}, | ||
'value': str(value) | ||
} | ||
) | ||
|
||
response = { | ||
'options': options | ||
} | ||
|
||
print(json.dumps(response)) | ||
return { | ||
'statusCode': 200, | ||
'body': json.dumps(response), | ||
"headers": { | ||
'Content-Type': 'application/json', | ||
} | ||
} | ||
|
||
|
||
return { | ||
'statusCode': 200 | ||
} | ||
|
||
|
||
|
||
return { | ||
'statusCode': 404, | ||
'body': json.dumps('No search value provided') | ||
} | ||
|
||
return { | ||
'statusCode': 404, | ||
'body': json.dumps('No payload provided') | ||
} |
Oops, something went wrong.