I want to upload video into S3 using AWS lambda function. This video is not available in my local computer. I have 'download URL'. I don't want to download it into my local computer and upload it into S3. I am looking for a solution to directly put this video file into S3 using lambda function. If I use buffer or streaming, I will consume lots of memory. Is there a better efficient solution for this?
I really appreciate your help.
Nowadays, there is a growing demand for serverless architecture, which makes uploading files to AWS S3 using API gateway with AWS Lambda (NodeJs) extremely useful. By simply following the above steps, you can make your own API to upload your files to S3 buckets on AWS.
In the Amazon S3 console, choose the bucket where you want to upload an object, choose Upload, and then choose Add Files. In the file selection dialog box, find the file that you want to upload, choose it, choose Open, and then choose Start Upload. You can watch the progress of the upload in the Transfer pane.
Sign in to the AWS Management Console and open the Amazon S3 console at https://console.aws.amazon.com/s3/ . In the Buckets list, choose the name of the bucket that you want to upload your folders or files to. Choose Upload.
I had the same question and developed the following quick solution that is not dependent on the /tmp
disk limits. It uses download stream as a file-like object.
Features:
Using configurable upload_fileobj builtin multipart and threaded upload
import boto3
import botocore.vendored.requests.packages.urllib3 as urllib3
def lambda_handler(event, context):
url='http://yourdownloadurl/file.tgz' # put your url here
bucket = 'aws-s3-bucket' #your s3 bucket
key = 'folder/filename' #your desired s3 path or filename
s3=boto3.client('s3')
http=urllib3.PoolManager()
s3.upload_fileobj(http.request('GET', url,preload_content=False), bucket, key)
You could certainly write an AWS Lambda function that would:
/tmp
It would be easiest to download the complete file rather than attempting to stream it in 'bits'. However, please note that there is a limit of 500MB of disk space available for storing data. If your download is larger than 500MB, you'll need to do some creative programming to download portions of it and then upload it as a multi-part upload.
As for how to download it, use whatever library you prefer for download a web file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With