Amazon s3 boto3: Check if upload is done - python-3.x

I'm having a user upload a file to s3 storage directly. My issue is that while that file is uploading, I want to run a worker to check if the upload is done, and if it is, do some processing.
If a file upload is in progress, is there a way I can find it from boto3 separately using it's key and bucket? If I can find it, can I check if the upload is done?

Please check S3Transfers
It takes callBack parameter which gives you upload/download percentage.

Related

How to check if a file is uploaded to S3 bucket in last X days using Node.JS

I'm a node js developer and new yo AWS. I'm working on a task related where I need to check whether a file being uploaded to S3 bucket in last 90 days or not.
Usually when a file is uploaded to S3, Lambda will be triggered and it's data being stored into Cache.
But if not uploaded, I need to trigger a Lambda function and load that file's data to Cache.
Is there any way to check if a file is uploaded to S3 bucket using Node.JS so that I could trigger the Lambda.
Does Cron Job useful to check for the file upload or is there any better approach to do this.

Streaming uploading to S3 using presigned URL

I'm trying to upload a file into a customer's S3. I'm given a presigned URL that allows me to do a PUT request. I have no access to their access and secret key so the use of the AWS SDK is out of the question.
The use case is that I am consuming a gRPC server streaming call and transforming it into a csv with some field changes. As the calls come in, I would want to be able to stream the transformed gRPC response into S3. I would need to do it via streaming cause the response can get rather large, upwards of >100mb, so loading everything into memory before uploading it into S3 is not ideal. Any ideas?
This is an open issue with pre-signed S3 upload URL:
https://github.com/aws/aws-sdk-js/issues/1603
Currently, the only working solution for large upload through S3 pre-signed URL is to use multi-part upload. The biggest drawback of that approach is you need to let the server that signs the upload know the size of your file, as it will need to pre-sign each part individually. e.g: 100MB file upload will require 20 parts (each 5MB maximum) to be pre-signed individually.

AWS Lambda Function - Image Upload - Process Review

I'm trying to better understand how the overall flow should work with AWS Lambda and my Web App.
I would like to have the client upload a file to a public bucket (completely bypassing my API resources), with the client UI putting it into a folder for their account based on a GUID. From there, I've got lambda to run when it detects a change to the public bucket, then resizing the file and placing it into the processed bucket.
However, I need to update a row in my RDS Database.
Issue
I'm struggling to understand the best practice to use for identifying the row to update. Should I be uploading another file with the necessary details (where every image upload consists really of two files - an image and a json config)? Should the image be processed, and then the client receives some data and it makes an API request to update the row in the database? What is the right flow for this step?
Thanks.
You should use a pre-signed URL for the upload. This allows your application to put restrictions on the upload, such as file type, directory and size. It means that, when the file is uploaded, you already know who did the upload. It also prevents people from uploading randomly to the bucket, since it does not need to be public.
The upload can then use an Amazon S3 Event to trigger the Lambda function. The filename/location can be used to identify the user, so the database can be updated at the time that the file is processed.
See: Uploading Objects Using Presigned URLs - Amazon Simple Storage Service
I'd avoid uploading a file directly to S3 bypassing the API. Uploading file from your API allows you to control type of file, size etc as well as you will know who exactly is uploading the file (API authid or user id in API body). This is also a security risk to open a bucket to public for writes.
Your API clients can then upload the file via API, which then can store file on S3 (trigger another lambda for processing) and then update your RDS with appropriate meta-data for that user.

Transferring a very large image from the web to S3 using AWS Lambda

I have access to a 20 GB image file from the web that we'd like to save on S3.
Is it possible to do this with AWS Lambda? From how I understand the situation, the limitations seem to be the following:
The lambda memory (can't load the whole image into memory)
Now if we decide to stream from the web to S3 (say using requests.get(image_url, stream=True) or smart_open..
the lambda reaching its timeout limit, along with..
S3 not supporting appending to S3 objects. Thus, succeeding lambda runs to continue "assembling" the image on S3 (where preceding ones left off) will have to load the partial image that's already on S3 into memory, before it can start appending more data, and uploading the resulting larger partial image to S3.
I've also heard of others suggesting to use multi-part uploads. But I'd be happy to know how that's different from streaming, and how that will overcome the limitations listed above.
Thank you!
Things are much simplified with s3.
Create a lambda to generate pre-signed url for multipart upload.
Create Multipart Upload:
http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#createMultipartUpload-property
Create Signed URL with the above Multipart Upload Key:
http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#getSignedUrl-property
Use that url to upload multiple parts of your file parallel.
You can also use S3 accelerator for high-speed upload.
Hope it helps.
EDIT1:
You can split the file in chunk between 1 to 10,000 and upload them parallelly.
http://docs.aws.amazon.com/AmazonS3/latest/dev/mpuoverview.html
If you are doing only one file upload, you can generate the signedurl and multipart in the cli rather than lambda.
If you are doing regularly, you can generate them via lambda.
When you read the file to upload, if you read them via HTTP, read them in a chunk and upload in multipart.
If you are reading the file locally, you can have the starting point of the file for each chunk and upload them with multipart.
Hope it helps.

How to upload image directly to S3 with NodeJS

went on NPMJS but could't find any libraries useful. It looks like nearly all of them requires it first to be stored on the server then upload to S3. Any chance the file can be uploaded directly to S3?
These two links are good sources of uploads to S3.
http://blog.katworksgames.com/2014/01/26/nodejs-deploying-files-to-aws-s3/
http://docs.aws.amazon.com/AWSJavaScriptSDK/guide/node-examples.html
This blog post explains in detail how you can solve this problem:
https://www.terlici.com/2015/05/23/uploading-files-S3.html
You need to create a signed URL first and after that a user can upload a file directly to S3.

Resources