Amazon web services AWS Lambda函数无限地从运动流读取记录

Amazon web services AWS Lambda函数无限地从运动流读取记录,amazon-web-services,amazon-kinesis,aws-lambda,Amazon Web Services,Amazon Kinesis,Aws Lambda,我有一个包含一个碎片和一个用python编写的lambda函数的运动流。我添加了kinesis流作为批处理大小为5的事件源。我向kinesis添加了数百条记录,lambda函数被正确调用和执行。但对于最后3条记录,lambda函数被无限调用,即使函数返回成功 Lambda函数: from __future__ import print_function import base64 import json import urllib2 import json print('Loading fu

我有一个包含一个碎片和一个用python编写的lambda函数的运动流。我添加了kinesis流作为批处理大小为5的事件源。我向kinesis添加了数百条记录,lambda函数被正确调用和执行。但对于最后3条记录,lambda函数被无限调用,即使函数返回成功

Lambda函数:

from __future__ import print_function

import base64
import json
import urllib2
import json

print('Loading function')

def is_valid_url(url):
    try:
        urllib2.urlopen(url)
        print("Valid URL ...")
        return True         # URL Exist
    except ValueError, ex:
        print("URL is not formatted...")
        return False        # URL not well formatted
    except urllib2.URLError, ex:
        print("Invalid URL ...")
        return False        # URL don't seem to be alive


def lambda_handler(event, context):     
    for record in event['Records']:
        # Kinesis data is base64 encoded so decode here
        payload = base64.b64decode(record['kinesis']['data'])
        params = json.loads(payload)
        print("Decoded payload: " + payload  + " : " +     str(is_valid_url(params['url'])) + " : " + str(len(event['Records'])))
    return 'Successfully processed {} records.'.format(len(event['Records']))
````

当我看云监控日志时

  START RequestId: d6033244-1c43-40ea-8886-f38b8c48daa3 Version:   $LATEST 
  Loading function 
  Valid URL ... 
  Decoded payload: { "url": "https://google.com" }
  Valid URL ... 
  Decoded payload: { "url": "https://google.com" }
  Valid URL ... 
  Decoded payload: { "url": "https://google.com" }
  Valid URL ...  
  Decoded payload: { "url": "https://google.com" }
  END RequestId: d6033244-1c43-40ea-8886-f38b8c48daa3 
  REPORT RequestId: d6033244-1c43-40ea-8886-f38b8c48daa3    Duration: 3003.00 ms    Billed Duration: 3000 ms Memory Size: 128 MB    Max Memory Used: 10 MB   
  2016-03-04T17:32:01.030Z d6033244-1c43-40ea-8886-f38b8c48daa3 Task timed out after 3.00 seconds

我不知道lambda函数发生了什么。有人能提供一些关于此错误的见解吗。

因为您的函数正在超时,Lambda将运行视为错误。Kinesis的错误处理策略是重试记录,直到它脱离修剪范围(通常为24小时),因此您的函数将重试24小时或直到它没有超时


根据你发布的内容,我不知道你的功能为什么超时。一个快速修复方法是简单地增加Lambda控制台上的超时值(在“配置”选项卡上的“高级”下)

关于在每个批中只读取5个事件的注释:您将快速开始累积处理延迟,因为您可以每秒向碎片写入1000个事件,并且应该计划在每秒钟内处理所有url。由于某些原因,ping某些url需要3秒以上的时间,所以增加超时时间效果很好。谢谢你的回复