Serverless AWS with EC2

0

Hi, I've developed a web application for image segmentation where users can upload an image and select a specific segmentation method (AI model). The image is processed on an EC2 instance, and the results are sent back to the user. This application was built using the Flask library in Python, and I've deployed the files on EC2, linking them to a domain. I opted for EC2 to utilize its GPU capabilities for model execution.

However, I'm encountering a cost-efficiency issue, as the EC2 instance needs to run continuously. I am now exploring more efficient alternatives and am considering AWS Lambda to trigger the EC2 instance only when a user uploads an image. This would allow the instance to process the image, send the results back, and then shut down, potentially reducing running costs.

Since I'm not very familiar with AWS Lambda, I'm unsure if this is the most optimized approach. I would greatly appreciate your insights on this. Additionally, if AWS Lambda is a viable solution, any references or step-by-step guides you could share would be extremely helpful.

Thank you in advance for your assistance.

asked 5 months ago134 views
2 Answers
0

Hello.

As you can see, Lambda can be used for such use cases.
For example, you can trigger a Lambda when an image is uploaded to S3.
https://docs.aws.amazon.com/lambda/latest/dg/with-s3-example.html

If you want to do it without using Lambda, I think it is better to use SQS CloudWatch metrics and configure it to start automatically with EC2 AutoScaling.
Trigger SQS and accumulate a queue when images are uploaded to S3.
I think if you set it to scale according to the number of queues, you will be able to start processing when necessary.
https://docs.aws.amazon.com/autoscaling/ec2/userguide/as-using-sqs-queue.html
https://dev.to/aws-builders/auto-scale-ec2-using-sqs-306e

profile picture
EXPERT
answered 5 months ago
  • Thank you for the tip. I am thinking to use lambda function as I already took an online course to learn how to deploy web app with lambda. I am wondering how can I start and stop an EC2 instance with lambda when a new image is uploaded by user.

0

Hey, this works for starting and stopping the EC2 instances using Lambda function. https://repost.aws/knowledge-center/start-stop-lambda-eventbridge

In the lambda trigger section go with S3 trigger rather than eventbridge as per your requirement. https://docs.aws.amazon.com/lambda/latest/dg/with-s3-example.html

profile picture
answered 5 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions