【发布时间】:2019-07-08 14:10:56
【问题描述】:
我是 Lambda 新手,正在尝试模拟一个简单的函数来对 Kinesis Fireshose 执行 PUT。
我尝试通过 AWS 文档查找,但找不到任何确切的参考来编写简单的 python 脚本以从 API 执行 GET 并通过 Firehose 将 JSON 发送到 S3。下面是我尝试发布到 Lambda 的代码,但我想按计划将其发送到 Firehose,而不是文件系统。
# 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.'
【问题讨论】:
标签: python-3.x amazon-web-services amazon-kinesis