AWS Lambda reduce request image size - amazon-web-services

I am currently sending an image file to API Gateway, that then runs a lambda function for compression and storing in s3. Is there a way to limit the image size to make it maximum 1MB? I don't want to run my lambda function for huge images?

Related

What is the best way to upload multiple images in aws s3

i am creating a website and users can upload maximum 15 images. I store images and resized images(with aws lambda function) in aws s3, but if i send images to aws s3 one by one it will be too expensive for aws s3 bill. Should i zip them in a folder and send to aws s3, after that unzip them and resize them in aws? thanks for answers.
I am using react-springboot.
Storing in zip will help you reduce the per request cost for s3 and a little space (since zip files may not affect much to images, depending on the zip compression used).
For every user upload example(approx. cost as per AWS site):
Not Storing: $0.000005 per put request X 15 + $0.000004 per Get request X 15
Storing as ZIP: $0.000005 X 1 + 0.000004 X 1
Other options include why not resize the images in Lamda (Async call) and then directly store to AWS S3. This depends on the time your function takes which will incur you additional cost.

AWS size limit on lambda output to be written to s3

I have to create a lambda that processes some payload and creates an output that is greater than the limit 6 MB for the response payload.
A way to solve this problem mentioned over various SO answers is to directly put the file on an s3.
But what these answers fail to mention is the upper limit of the output that can be saved into the s3 by the lambda. Is it because there isn't any limit?
I just want to confirm this before moving forward.
There are always limits. So yes, there is also a limit of object size in a S3 bucket. But before you hit that limit, you are going to hit other limits.
Here is the limit of uploading files using the API:
Using the multipart upload API, you can upload a single large object, up to 5 TB in size.
(Source)
But you are probably not going to be able to achieve this with a Lambda, since Lambdas have a maximum running time of 900 seconds. So even if you could upload a file at 1GB/s, you only would be able to upload 900GB before the Lambda stops.

Large Data transfer using AWS Lambda and AWS S3

We have to create a large zip outputstream (500 MB - 1 GB max file size) using AWS Lambda (Java) and transfer it to S3. I am facing an issue here:
a. Connection timeout as the file is large
If the zip file is small, then it is working fine.
When I checked, it seems like multi-part upload might help. I am yet to try it, but wanted to know if there is a better option.
Does file transfer from AWS Lambda to S3 happens over Internet? Is there any way where I can use AWS optimized network since I do not have any need to use data from outside AWS network (the zip data is created within Lambda only). Will that help in faster data transfer?
The other option is to use multi part upload using Java (since we are a Java shop).
I understand that AWS Lambda has an execution timeout of 15 minutes. So if the data transfer takes long time, instead of a connection timeout, we might hit Lambda execution timeout. That is also not acceptable. So a fast data transfer would really help. The processing is trivial otherwise - I have to keep the Lambda running only because the data transfer takes long time.
Thanks in advance.

Saving mp3 tag data to AWS DynamoDB via API Gateway

I tried to save MP3 tag metadata to DynamoDB via API Gateway with a Lambda proxy, but that fails on certain files with:
PayloadTooLargeError: request entity too large
The main culprit was the (often present) picture param, which includes a buffer array, which varies in size/length depending on the album art.
What I wound up doing converting the buffer array into a dataURL and storing that in S3, and referencing it in DynamoDB, which works, but results in a lot more API calls and more complexity than just storing the buffer array (converted to base64) in DynamoDB directly.
Has anyone successfully and consistently stored mp3 tag data, including cover art in DynamoDB via the API Gateway, and, if so, how? Or is using S3 the only way to fly with this?
Your question isn't really related to MP3, as it applies to all large data you want to pass through API Gateway.
API Gateway has a limit of 10MB for the payload size and there is no way of circumventing this limitation.
Even if you'd be able to pass the images through API Gateway, you wouldn't be able to store them in DynamoDB, as each item there has a size limit of 400KB.
Unless you're open to scaling the images down to <400KB before sending the request, I'm afraid your current solution with S3 to store the images is the best you can do.

Can't Upload 5MB - 10MB image file to Lambda through API gateway

I am trying to upload 5MB image to aws lambda through api gateway.
I need to pass the file content as binary or buffer without any conversion. But API gateway converts the input as base64
by default and the converted base64 text is 7MB. As the data size is increased after base64 conversion lambda is not allowing that size.
How to prevent this automatic base64 conversion in API Gateway?
In AWS forum most of them were suggested to upload the file to s3 bucket and use that in lambda. But in my case i need to pass it directly to lambda without the help of S3. I have been at this for some weeks now....any help or insight is appreciated.
As documented, the maximum payload size for synchronous invocation (as from API Gateway) is 6 MB.
That means that, if you have larger payloads, you will need to break them up into multiple requests and combine those requests for processing. Which means that you need some form of storage to hold the pieces, and a way to link the pieces together.
If you need to upload a larger payload in a single request, and can't use an alternative such as uploading to S3 first, then Lambda isn't for you.