5
|
1 import json
|
|
2 import boto3
|
|
3 from boto3.dynamodb.conditions import Key
|
|
4
|
|
5 resource = boto3.resource('dynamodb')
|
|
6 table = resource.Table('FinanceParser')
|
|
7
|
|
8
|
|
9 def lambda_handler(event, context):
|
7
|
10 response = table.scan(
|
|
11 FilterExpression=Key('pk').begins_with('file')
|
5
|
12 )
|
|
13
|
13
|
14 results = []
|
|
15 for item in response['Items']:
|
|
16 item_pk = item['pk'].split('#', 1)[1]
|
|
17 item_year = item['sk'].split('#', 1)[0]
|
|
18 item_key = f'{item_pk}#{item_year}' # pnl#acx#2022
|
|
19
|
|
20 if item_key not in results:
|
|
21 results.append(item_key)
|
|
22
|
5
|
23 return {
|
|
24 "statusCode": 200,
|
7
|
25 "headers": {
|
|
26 "Access-Control-Allow-Headers": "Content-Type",
|
|
27 "Access-Control-Allow-Origin": "*",
|
|
28 "Access-Control-Allow-Methods": "GET"
|
|
29 },
|
5
|
30 "body": json.dumps({
|
|
31 "message": {
|
13
|
32 "items": results,
|
|
33 "count": len(results)
|
5
|
34 }
|
|
35 }),
|
|
36 }
|