-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtest copy.json
More file actions
35 lines (24 loc) · 751 Bytes
/
test copy.json
File metadata and controls
35 lines (24 loc) · 751 Bytes
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
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):
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('Sales')
response = table.scan(
FilterExpression=Key('orderYear').eq(2017)
)
sortedList = sorted(response["Items"], key = lambda i: i['total'])
body = json.dumps(sortedList[:10], cls=DecimalEncoder)
return {
'statusCode': 400,
'body': body
}
lorem