[server]: Update return_newest_data and add test script
This commit is contained in:
@ -8,15 +8,18 @@ table = dynamodb.Table(os.environ['TABLE_NAME'])
|
||||
|
||||
def lambda_handler(event, context):
|
||||
try:
|
||||
# Scan the table to get all items
|
||||
response = table.scan(
|
||||
FilterExpression=Attr('timestamp').exists()
|
||||
)
|
||||
items = response['Items']
|
||||
|
||||
newest_timestamp = max([int(item['timestamp'] for item in items)])
|
||||
newest_timestamp = max([int(item['timestamp']) for item in items])
|
||||
newest_items = [item for item in items if int(item['timestamp']) == newest_timestamp]
|
||||
|
||||
# assuming that filtering by timestamp first makes sense, as we expect to have a lot of historical data and not many object types
|
||||
if 'queryStringParameters' in event and event['queryStringParameters'] and 'objectType' in event['queryStringParameters']:
|
||||
newest_items = [item for item in items if item['objectType'] == event['queryStringParameters']['objectType']]
|
||||
|
||||
return {
|
||||
'statusCode': 200,
|
||||
'body': json.dumps(newest_items)
|
||||
|
9
server/src/test/return_newest_data/return_newest_data.sh
Executable file
9
server/src/test/return_newest_data/return_newest_data.sh
Executable file
@ -0,0 +1,9 @@
|
||||
#!/bin/sh
|
||||
|
||||
API_URL="https://281bc6mcm5.execute-api.us-east-1.amazonaws.com/transient_data"
|
||||
|
||||
if [ "$1" ]; then
|
||||
query_string="?objectType=$1"
|
||||
fi
|
||||
|
||||
curl "$API_URL$query_string"
|
Reference in New Issue
Block a user