python-3.x - 在 Firehose 中为 PUT 编写 AWS Lambda 函数
问题描述
我是 Lambda 新手,正在尝试模拟一个简单的函数来将 PUT 放入 Kinesis Fireshose。
我尝试通过 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.'
解决方案
以下是AWS 中用于写入 S3的示例代码的链接以及适用于 Python 的 Amazon Web Services (AWS) SDK 的文档。
此外,您还可以查看Amazon Kinesis Data Firehose api 参考文档
推荐阅读
- python - 如何删除 Python 字符串列表的特定列?
- javascript - 如何在 ReactJS 中关闭弹出窗口之前等待函数?
- python-3.x - Python 3 matplotlib 添加具有多个比例轴的水印
- python - 在 python GUI 中显示打印输出?
- hadoop - 在伪分布式模式下启动 HBase 失败抛出“Failed construction RegionServer”
- javascript - ServiceNow - 列表仅使用最后一个值更新
- javascript - 如何在删除包含 discord.js 的嵌入之前设置延迟?
- java - Spring Boot addObject 无法正常工作
- python - 我不知道如何在 PyCharm 中安装熊猫
- assembly - 在 x86_64 中,如果条件为假,32 位 cmov 是否会清除最高位?