-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrestAPI.py
More file actions
47 lines (36 loc) · 1.23 KB
/
restAPI.py
File metadata and controls
47 lines (36 loc) · 1.23 KB
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
44
45
46
47
from flask import Flask, request, jsonify
from flask_restful import Resource, Api
import boto3
from botocore.exceptions import ClientError, ParamValidationError
import os
from dotenv import load_dotenv
load_dotenv("bedrock/.env")
app = Flask(__name__)
api = Api(app)
access_key_id = os.getenv("AWS_ACCESS_KEY_ID")
secret_access_key = os.getenv("AWS_SECRET_ACCESS_KEY")
dynamodb = boto3.client(
service_name='dynamodb',
aws_access_key_id=access_key_id,
aws_secret_access_key=secret_access_key,
region_name='us-west-2',
)
class GetItem(Resource):
def get(self):
try:
ticker = request.args.get('ticker')
if not ticker:
return {"error": "Missing key parameter"}, 400
response = dynamodb.get_item(
TableName='Investify_DynamoDB',
Key={'Ticker': {'S': ticker}}
)
if 'Item' in response:
return response['Item'], 200
else:
return {"error": "Item not found"}, 404
except (ClientError, ParamValidationError) as e:
return {"error": str(e)}, 500
api.add_resource(GetItem, '/get_item')
if __name__ == '__main__':
app.run(debug = True)