MultiCloud Classroom notes 12/mar/2026

Serverless Compute:

  • Serverless compute enables running code or containers without managing servers. The cloud provider automatically handles infrastructure provisioning, scaling, patching, and availability.

  • Developers focus only on application logic, while the platform manages the backend infrastructure.

Max execution time limits 15 min

Common integrations include:

  • Amazon API Gateway:

    • restapi: 30 sec
    • http
    • webscoket api
  • Amazon S3:

    • upload files…events
  • Amazon DynamoDB:

    • event
  • Amazon EventBridge:

    • based metrix
    • trigger cron
  • Pricing Model

Lambda pricing is based on:

  • Number of requests

  • Execution duration

  • Memory allocation (GB-seconds)

  • Additional costs may include:

  • Provisioned concurrency

please follow class recording and create lambda and layers

Lambda sample code to start/stop ec2 insatnce

import boto3

def lambda_handler(event, context):
    ec2 = boto3.client('ec2')

    tag_key = event.get('tag_key', 'Schedule')
    tag_value = event.get('tag_value', 'StartStop')
    action = event.get('action')

    response = ec2.describe_instances(
        Filters=[{'Name': f'tag:{tag_key}', 'Values': [tag_value]}]
    )

    results = []

    for reservation in response['Reservations']:
        for instance in reservation['Instances']:
            instance_id = instance['InstanceId']
            state = instance['State']['Name']

            if action == 'start' and state == 'stopped':
                ec2.start_instances(InstanceIds=[instance_id])
                results.append(f"Started {instance_id}")

            elif action == 'stop' and state == 'running':
                ec2.stop_instances(InstanceIds=[instance_id])
                results.append(f"Stopped {instance_id}")

            else:
                results.append(f"Instance {instance_id} is already {state}")

    # ✅ Return a structured response
    return {
        "statusCode": 200,
        "body": {
            "action": action,
            "tag_key": tag_key,
            "tag_value": tag_value,
            "results": results
        }
    }

payload to trigger lambda


{
  "action": "start",
  "tag_key": "Environment",
  "tag_value": "dev"
}

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