forked from bonjon/CloudComputingProject
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlambda_function.py
More file actions
executable file
·39 lines (33 loc) · 1.04 KB
/
lambda_function.py
File metadata and controls
executable file
·39 lines (33 loc) · 1.04 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
import json
import requests
from io import StringIO # python3 (or BytesIO for python2)
import boto3
import os
def lambda_handler(event, context):
parameters = {"start": str(event["start"]), "timeframe": str(event["timeframe"])}
headers = {
"Apca-Api-Key-Id": os.environ["ApcaApiKeyId"],
"Apca-Api-Secret-Key": os.environ["ApcaApiSecretKey"],
}
response = requests.get(
url=str(event["base_url"])
+ str(event["sub_url"])
+ str(event["symbol"])
+ str(event["query_url"]),
headers=headers,
params=parameters,
)
csv_buffer = StringIO(str(response.json()))
s3_resource = boto3.resource("s3")
s3_resource.Object(os.environ["bucketName"], str(event["symbol"]) + ".json").put(
Body=csv_buffer.getvalue()
)
return {
"statusCode": 200,
"body": "OK for query: "
+ str(event["symbol"])
+ " from:"
+ str(event["start"])
+ " in:"
+ str(event["timeframe"]),
}