Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 编写AWS Lambda函数以插入消防软管_Python 3.x_Amazon Web Services_Amazon Kinesis - Fatal编程技术网

Python 3.x 编写AWS Lambda函数以插入消防软管

Python 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

我是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, 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

此外,您还可以签出文档