Python 3.x 编写AWS Lambda函数以插入消防软管
我是Lambda的新手,正在尝试模拟一个简单的函数,将其放入Kinesis Fireshose 我试着浏览AWS文档,但找不到任何确切的参考来编写一个简单的python脚本,从API获取JSON,并通过Firehose将JSON发送到S3。下面是我试图发布到Lambda的代码,但我不想使用文件系统,而是希望按计划将其发送到FirehosePython 3.x 编写AWS Lambda函数以插入消防软管,python-3.x,amazon-web-services,amazon-kinesis,Python 3.x,Amazon Web Services,Amazon Kinesis,我是Lambda的新手,正在尝试模拟一个简单的函数,将其放入Kinesis Fireshose 我试着浏览AWS文档,但找不到任何确切的参考来编写一个简单的python脚本,从API获取JSON,并通过Firehose将JSON发送到S3。下面是我试图发布到Lambda的代码,但我不想使用文件系统,而是希望按计划将其发送到Firehose # Get weather from OWM and use args for correct type. def get_weather(gtype, la
# 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和 AmazonWebServices(AWS)Python的SDK 此外,您还可以签出文档