我有一個kinesis流,其中包含一個分片和一個用python編寫的lambda函數。我添加了kinesis流作爲批處理大小爲5的事件源。我將幾百條記錄添加到kinesis中,並且lambda函數被正確調用和執行。但是對於最後3條記錄,即使函數返回成功,lambda函數也會無限調用。AWS Lambda函數從kinesis流中無限讀取記錄
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']))
````
當我看着雲watch日誌
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函數發生。有人可以提供一些見解這個錯誤。
關於每批讀取僅5個事件的註釋:您可以快速開始在處理中積累延遲每秒1000個事件到碎片,並應計劃在每秒處理所有這些事件。 – Guy