MultiCloud Classroom notes 22/Aug/2026

AWS Lambda: Practical Use Cases & Automations

AWS Lambda is a highly versatile serverless compute service used for both event-driven data processing and infrastructure automation. Below are key examples of how it is utilized in real-world scenarios.

1. Event-Driven Processing: Image Resizing

Scenario: Reducing the size of user-uploaded images to meet organizational standards.

The Workflow

  1. Upload: A user uploads a high-resolution image to an Amazon S3 bucket.
  2. Event Trigger: S3 generates an ObjectCreated event, which automatically invokes the Lambda function.
  3. Execution: The Lambda function runs the resizing script. Lambda supports multiple languages (Python, Node.js, Java, .NET, etc.), allowing you to use standard image-processing libraries.
  4. Output: The optimized image is saved back to a destination S3 bucket.

Required IAM Permissions

To securely execute this workflow, the Lambda function requires an Execution Role with the following policies attached:

  • Lambda Execution: AWSLambdaBasicExecutionRole (allows the function to run and write logs to CloudWatch).
  • S3 Access: Permissions to read from the source bucket (s3:GetObject) and write to the destination bucket (s3:PutObject).

2. Dependency Management: Lambda Layers

When your code requires external libraries (e.g., Pillow for image processing or requests for API calls), package them into a Lambda Layer instead of the main deployment package.

Example: Downloading an Image from S3 (Python / Boto3)

Note: boto3 is included in the AWS Lambda Python runtime by default, so it does not require a custom layer.

import boto3
import os

s3_client = boto3.client('s3')

def download_image(bucket_name, object_key, download_path):
    \"\"\"Downloads an image from S3 to the Lambda local /tmp storage\"\"\"
    try:
        s3_client.download_file(bucket_name, object_key, download_path)
        print(f"Successfully downloaded {object_key} to {download_path}")
    except Exception as e:
        print(f"Error downloading file: {str(e)}")
        raise e
  1. Cloud & DevOps Automations Lambda is a powerful tool for enforcing governance and automating repetitive SysAdmin tasks.

Use Case A: Resource Tagging Compliance

Organizations require strict tagging standards for cost tracking and security.

Trigger: An Amazon EventBridge rule (Cron Job) triggers the Lambda function every 1 hour.

Validation: The Python script uses boto3 to scan resources and check if mandatory tags exist.

Remediation: If tags are missing, Lambda automatically applies temporary tags (e.g., Compliance: Failed, Date_To_Terminate: <Date>).

Notification: Lambda triggers an Amazon SNS topic to send an email alert to the responsible team, warning them of the upcoming termination.

Use Case B: Instance State Management

To save costs, environments should only run when needed.

Action: Lambda scans for EC2 instances based on specific team tags (e.g., Team: usi-us).

Execution: Depending on the time of day, Lambda issues stop_instances(), start_instances(), or reboot_instances() commands to automate the environment’s uptime schedule.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Please turn AdBlock off
Social Media Icons Powered by Acurax Web Design Company

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Visit Us On FacebookVisit Us On LinkedinVisit Us On Youtube