On an hourly basis I have to download files ranging from 6-10Gb and on a daily basis I have to download a file that ranges from 25-45Gb and monthly the file ranges from 400-500Gb. Currently this is all being done using perl and it works great but now we are moving to AWS and Lambda and with Lambda's 15 minute max process time my code times out. If I happen to have a files that is less than 5.5Gb the lambda python function I have written works just fine. So my hope is that someone has had to tackle this sort of problem and can help me out. Here is a stripped down version of the function as it sits right now.
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)