FAQ’s On Serverless Image Processing with AWS Lambda and S3
1. Why Two Different S3 Buckets Are Used For Uploaded And Processed Images?
Whenever the lambda function uploads the processed images to the source bucket it will create 2 triggers and the function will process the 2 images once again which then creates 4 triggers. This creates an infinite loop and generates many images, so we created two buckets to prevent an infinite loop.
2. How To See The Logs Of My Lambda Function ?
Go to CloudWatch > Log groups > ImageProcessing . There you will see multiple log streams with their corresponding time stamps. Click on any of them to see the logs.
3. Why Is The Processed Image Not Uploaded Into My S3 Bucket ?
Make sure you followed the tutorial properly. There can be several reasons for the processed image not being uploaded to the S3 bucket.
- Check the source code of you lambda function. The value of processedImageBucket variable should be the name of your destination S3 bucket where the processed images are to be stored. No type should be there.
- Make sure the bucket policy is configured correctly and it has all the permissions required for the S3 bucket.
- Check the timeout of your Lambda function in the Configuration tab. It should be around 30 s to 1 min. If the timeout is low then your Lambda function will be terminated before it can upload the processed image to the bucket.
- Make sure that the S3 trigger is set properly and the Lambda function is added to it. Check Step 5 once again.
4. Why Use Lambda Function Instead Of EC2 ?
EC2 instance is continuosly running and charged for the whole time. Lambda function runs only when it is requested. (when an image is uploaded) and it is charged only for the time it is runs. So depending on the use case Lambda function can be more cost effective than EC2.
5. Why Lambda Layer Is Used Instead Of Installing The Dependencies In The Code Itself?
You can include the dependencies in the code itself instead of creating a Lambda layer for it but doing so will increase the size of your code. Using Lambda layers you can create a separate layer for your dependencies and then reuse it in another Lambda function which requires same dependencies which reduces the code size and complexity as you do not have to include the dependencies in all functions. Instead you can just attach the layer to the Lambda functions in which it is required.
Serverless Image Processing with AWS Lambda and S3
AWS S3 (Simple Storage Service) is a cloud data storage service. It is one of the most popular services of AWS. It has high scalability, availability, security and is cost effective. S3 has different storage tiers depending on the use case. Some common use cases of AWS S3 are:
- Storage: It can be used for storing large amounts of data.
- Backup and Archive: S3 has different storage tiers based on how frequent the data is accessed which can be used to backup critical data at low costs.
- Static website: S3 offers static website hosting through HTML files stored in S3.
- Data lakes and big data analytics: Companies can use AWS S3 as a data lake and then run analytics on it for getting business insights and take critical decisions.