I wrote a script in Python to grab files from an SFTP server off-prem and download them into memory, then dump to s3.
However, I am getting absolutely abysmal network speeds. It’s taking almost 4 minutes to download a 70MB file. The exact calculation for network speed when I do the math is ~2.5mbps.
That’s like what my DSL was in college 20 years ago.
I’ve verified it’s not an SFTP server issue-- at my office I’m able to snatch it using the same exact code in seconds.
I have a number of files and some are like 30MB, so this approach which I thought would be a slam dunk is not looking so great anymore. Anybody ever run in to this, or know how to increased network speed?
Thanks.
Solved:
It’s not a lambda issue but a paramiko issue.
If you want to download to a file buffer in memory which is preferable for lambda, use getfo instead of file/read. See my comment below for code. After doing that things work incredibly well.
Interesting. I had the memory and time limit both pegged out (3000mb and 15 minutes respectively). Do you mean it’s inversely proportional? Like lowering memory will make it faster?
I was having an issue transferring about 50 gigs. I used the aws cli s3 cp command to go to s3
I then copied from s3 to the EC2 instance. For the EC2 to S3 I ran across some acceleration parameters. (posted latter) I went from S3 to EC2 in about 15 - 20 minutes. Home to S3 was several hours. Yea this was within AWS but it was much much faster.
About 1/2 way down are the parameters. I did not have an acceleration endpoint but it still worked, so delete that line. I also had some issues with what file to put this in .aws\credentials or .aws\config
I actually installed and uploaded Speedtest-cli to verify your exact findings.
I also figured out the problem. It was systemic from running in Lambda but also as part of the paramiko library defaulting to reading files in 32k chunks which is incredibly inefficient using file() and read().
When I switched to using BytesIO() and paramiko’s
getfo()
things started to really blaze. getfo stands for get file object.
In essence if anybody else comes looking this is a paramiko issue, and don’t use file but instead getfo like this:
from io import BytesIO
fileob = BytesIO()
sftp.getfo(remotePath, fileob)
# must do this or it won’t work
fileob.seek(0)
obj = s3.Object(bucket, key)
obj.put(Body=fileob)