-
Notifications
You must be signed in to change notification settings - Fork 8
/
temp2.txt
44 lines (27 loc) · 943 Bytes
/
temp2.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import boto3
import json
from boto3.dynamodb.conditions import Key
class DecimalEncoder(json.JSONEncoder):
def default(self, o):
if isinstance(o, decimal.Decimal):
if o % 1 > 0:
return float(o)
else:
return int(o)
return super(DecimalEncoder, self).default(o)
def lambda_handler(event, context):
print("debug:starting...")
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('Sales')
response = table.scan(
FilterExpression=Key('orderYear').eq(2017)
)
print(response["Items"])
# sortedList = sorted(response["Items"], key = lambda i: i['total'])
sortedList = sorted(response["Items"], key = lambda i: i['total'], reverse=True)
body = json.dumps(sortedList[:10], cls=DecimalEncoder)
# print("debug:body:"+body)
return {
'statusCode': 200,
'body': body
}