每小时我必须下载6-10 to的文件,每天我必须下载25-45 to的文件,每月下载400-500 to的文件。目前,所有这些都是使用perl完成的,它工作得很好,但现在我们正在转向AWS和Lambda,Lambda的最大处理时间为15分钟,我的代码超时了。如果我碰巧有一个小于5.5 is的文件,那么我编写的lambda python函数就可以正常工作。因此,我希望有人必须解决这类问题,并能帮助我解决问题。这是该函数的精简版本,就像它现在的样子。
import boto3
from botocore.exceptions import ClientError
import datetime
from datetime import datetime, timedelta
import dateutil.tz
import urllib3
import time
def lambda_handler(event, context):
http = urllib3.PoolManager()
s3 = boto3.client('s3')
s3object = boto3.resource('s3')
bucketName = "test-bucket"
checkDir = "check"
fileURL = 'https://export.dnsdb.info/dnsdb-export/mtbl/dns.20200930.0700.H.mtbl'
# Check to see if the file exists in S3 bucket
fileExists = True
try:
s3.head_object(Bucket=bucketName, Key=checkDir + '/' + file)
except ClientError as e:
fileExists = False
# If the file doesn't exist, download it
if not fileExists:
http = urllib3.PoolManager()
hdr={'X-API-Key' : 'api-key'}
response = http.request('GET', fileURL, preload_content=False, headers=hdr)
s3.upload_fileobj(response, bucketName, checkDir + '/' + file)
response = s3.head_object(Bucket=bucketName, Key=checkDir + '/' + file)发布于 2020-10-03 00:42:16
AWS Lambda每次执行只能使用15分钟。这意味着如果你的下载时间超过这个时间,你将会得到你所描述的超时。从本质上讲,你的下载速度是有限的,但在15分钟内获得500 GB的文件意味着下载速度>560MB/s,这在大多数情况下是不现实的。也许可以考虑使用EC2而不是Lambda。
发布于 2020-10-04 20:37:17
以下是一些想法:
https://stackoverflow.com/questions/64175119
复制相似问题