I'm new to Lambda and am trying to emulate a simple function to do a PUT into Kinesis Fireshose.
I have tried looking thru AWS docs, but am unable to find any exact references to write a simple python script to do a GET from an API and send JSON to S3 via Firehose. Below is the code I'm trying to post to Lambda, but instead of filesystem, I wanted to send this to Firehose on a scheduled basis.
# Get weather from OWM and use args for correct type.
def get_weather(gtype, lat, lon, key):
if gtype == 'current':
apitype = "weather?"
elif gtype == 'forecast':
apitype = "forecast?"
else:
print("Undefined GET type: use 'current' or 'forecast'.")
try:
api = "http://api.openweathermap.org/data/2.5/" + apitype
PARAMS = {'lat': lat, 'lon': lon, 'appid': key}
except:
return 'Invalid GET request'
with requests.session() as s:
rc = s.get(url=api, params=PARAMS)
data = rc.json()
return data
# Write data to json files.
def write_to_current(location, gtype, lat, lon, key):
with open(location + '/current.json', 'w') as outfile:
json.dump(get_weather(gtype, lat, lon, key), outfile)
return 'Current write complete.'