【问题标题】:Writing AWS Lambda function for PUT in Firehose在 Firehose 中为 PUT 编写 AWS Lambda 函数
【发布时间】: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


    【解决方案1】:

    这是一个指向来自 AWS 的示例 code 的链接,用于写入 S3 和 documentation 适用于 Python 的 Amazon Web Services (AWS) SDK。

    另外,您可以查看Amazon Kinesis Data Firehose api reference 文档

    【讨论】:

      猜你喜欢
      • 2018-08-08
      • 2021-01-03
      • 2019-07-18
      • 2018-10-29
      • 2021-02-17
      • 2016-04-10
      • 2020-09-15
      • 1970-01-01
      • 2018-07-02
      相关资源
      最近更新 更多