Functions Use-Case

Introduction

At E2E Networks, we offer a cutting-edge Function-as-a-Service (FaaS) platform as part of our comprehensive suite of cloud solutions. FaaS revolutionizes software development by enabling businesses to deploy individual functions in response to specific events or triggers, without the need to manage underlying server infrastructure.

Our FaaS offering provides scalability, cost-efficiency, agility, and reduced operational overhead, empowering businesses to rapidly develop, deploy, and scale applications while focusing on writing high-quality code and delivering value to customers. In this document, we are going to learn how we can integrate E2E object storage and Functions to manipulate objects stored in the bucket. We will see how we can apply image processing techniques like resizing, pixel management, image enhancement, compressing images etc using our Functions with Python runtime.

Translating User Images using E2E Functions:

Scenario

Consider a scenario where a business needs to process user-provided images to enhance their quality before storage or publication. This could involve tasks such as adjusting contrast, resizing images, or applying specific transformations.

Use Case: Image Enhancement with E2E Functions

Let’s examine a practical use case where our Functions platform facilitates image enhancement for user-provided images.

Step 1: Accessing Object Storage:

  • Connect to the specified object storage bucket using the provided access credentials.

  • Retrieve the image object from the designated bucket.

Step 2: Reading and enhance Image Content:

  • Read the content of the retrieved image object.

  • Open the image using the Pillow library.

  • Apply the desired image enhancement, such as increasing contrast, using the ImageEnhance module from Pillow.

  • Convert the enhanced image back to binary data for uploading.

Step 3: Uploading Enhanced Image:

  • Upload the enhanced image to the same object key in the storage bucket.

  • Handle any potential errors that may occur during the retrieval or processing of the image.



import io
import os
import json
from minio import Minio
from PIL import Image, ImageEnhance


BUCKET_URL = os.getenv("BUCKET_URL")
ACCESS_KEY = os.getenv("ACCESS_KEY")
SECRET_KEY = os.getenv("SECRET_KEY")


def handle(event, context):
# Initialize MinIO client
minio_client = Minio(BUCKET_URL,
                        access_key=ACCESS_KEY,
                        secret_key=SECRET_KEY,
                        secure=True)  # Adjust to True if using HTTPS


# Specify the bucket name and object key
bucket_name = 'faas-usecase'
object_key = '/image.webp'


try:
    # Retrieve the image object
    image_object = minio_client.get_object(bucket_name, object_key)
    # Read the image content
    image_content = image_object.read()
    # Open the image using Pillow
    image = Image.open(io.BytesIO(image_content))
    # Enhance the image (adjust enhancement factor as needed)
    enhancer = ImageEnhance.Contrast(image)
    enhanced_image = enhancer.enhance(2.0)  # Increase contrast by 20%
    # Convert the enhanced image back to binary data
    enhanced_image_binary = io.BytesIO()
    enhanced_image.save(enhanced_image_binary, format=image.format)
    # Rewind the buffer
    enhanced_image_binary.seek(0)
    # Upload the enhanced image to the same object key
    minio_client.put_object(bucket_name, object_key, enhanced_image_binary, len(enhanced_image_binary.getvalue()))
    return {
        "statusCode": 200,
        "body": "Image quality enhanced and replaced successfully"
    }
except Exception as e:
    # Handle any MinIO response errors that might occur during retrieval
    return {
        "statusCode": 500,
        "body": json.dumps({"error": str(e)})
    }

Once the enhancement process is complete, our FaaS function replaces the original user-provided images in the storage bucket with their enhanced versions. This seamless integration between object storage and FaaS ensures efficient image management and quality enhancement.

Benefits:

  • Asynchronous Image Processing: Perform image processing tasks asynchronously without impacting user experience, ensuring swift response times and seamless interaction with the application.

  • On-Demand Resource Utilization: Utilize resources efficiently by invoking functions only when required, eliminating the need for setting up and maintaining dedicated servers for image processing tasks. This approach optimizes resource utilization and reduces operational overhead.

  • Scalable and Responsive Architecture: Leverage a scalable architecture that dynamically allocates resources based on workload demands, enabling the system to scale seamlessly to handle varying levels of image processing requests while maintaining responsiveness and performance.

  • Efficient Resource Management: Effectively manage computing resources by leveraging serverless functions, which automatically scale up or down based on demand, optimizing resource utilization and minimizing costs associated with idle infrastructure.

Conclusion:

In summary, leveraging our function-as-a-service (FaaS) platform offers businesses a versatile and efficient solution for a wide range of tasks beyond image enhancement. By deploying functions in a serverless environment, organizations can streamline various processes, including data processing, automation tasks, API integrations, and more. This approach eliminates the need for managing infrastructure, allowing developers to focus solely on writing and deploying code. With E2E Functions, businesses can achieve scalability, cost-effectiveness, and agility, empowering them to innovate and adapt to evolving requirements seamlessly.