# HG changeset patch # User Dennis C. M. # Date 1685965727 -3600 # Node ID 2daf0dc08247ba0a3dd33e6d0b910077aefc565c # Parent 9005b7590008c4a6af28169f8ff88ca70cc22e3a add get report endpoint diff -r 9005b7590008 -r 2daf0dc08247 events/get_report_event.json --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/events/get_report_event.json Mon Jun 05 12:48:47 2023 +0100 @@ -0,0 +1,7 @@ +{ + "queryStringParameters": { + "ticker": "san", + "type": "balance", + "year": "2021" + } +} \ No newline at end of file diff -r 9005b7590008 -r 2daf0dc08247 get_report/__init__.py diff -r 9005b7590008 -r 2daf0dc08247 get_report/app.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/get_report/app.py Mon Jun 05 12:48:47 2023 +0100 @@ -0,0 +1,28 @@ +import json +import boto3 +from boto3.dynamodb.conditions import Key + +resource = boto3.resource('dynamodb') +table = resource.Table('FinanceParser') + + +def lambda_handler(event, context): + query_string_parameters = event['queryStringParameters'] + company_ticker = query_string_parameters['ticker'] + report_type = query_string_parameters['type'] + year = query_string_parameters['year'] + + pk = f'{report_type}#{company_ticker}' + response = table.query( + KeyConditionExpression=Key('pk').eq(pk) & Key('sk').begins_with(year) + ) + + return { + "statusCode": 200, + "body": json.dumps({ + "message": { + "items": response['Items'], + "count": len(response['Items']) + } + }), + } diff -r 9005b7590008 -r 2daf0dc08247 get_report/requirements.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/get_report/requirements.txt Mon Jun 05 12:48:47 2023 +0100 @@ -0,0 +1,1 @@ +boto3 \ No newline at end of file diff -r 9005b7590008 -r 2daf0dc08247 template.yaml --- a/template.yaml Mon Jun 05 10:13:43 2023 +0100 +++ b/template.yaml Mon Jun 05 12:48:47 2023 +0100 @@ -69,8 +69,6 @@ Type: AWS::Serverless::Function Properties: CodeUri: analyze_document/ - Handler: app.lambda_handler - Runtime: python3.7 Policies: - Version: "2012-10-17" Statement: @@ -91,8 +89,6 @@ Type: AWS::Serverless::Function Properties: CodeUri: process_document/ - Handler: app.lambda_handler - Runtime: python3.7 Connectors: S3Connector: Properties: @@ -106,8 +102,6 @@ Type: AWS::Serverless::Function Properties: CodeUri: upload_document/ - Handler: app.lambda_handler - Runtime: python3.7 Connectors: DynamoConnector: Properties: @@ -122,6 +116,40 @@ Permissions: - Read + Api: + Type: AWS::Serverless::Api + Properties: + StageName: Prod + Models: + Empty: + type: object + + GetReportFunction: + Type: AWS::Serverless::Function + Properties: + CodeUri: get_report/ + Events: + GetProductEvent: + Type: Api + Properties: + RestApiId: !Ref Api + Path: /report + Method: get + RequestParameters: + - method.request.querystring.ticker: + Required: true + - method.request.querystring.type: + Required: true + - method.request.querystring.year: + Required: true + Connectors: + DynamoConnector: + Properties: + Destination: + Id: DynamoTable + Permissions: + - Read + DynamoTable: Type: AWS::DynamoDB::Table Properties: