Featured image of post Exploring Lambda and Cloud Functions in GCP, AWS, & Azure Cloud

Exploring Lambda and Cloud Functions in GCP, AWS, & Azure Cloud

CheatSheet and Code Examples in Python and C#

A Brief History

  • Amazon Web Services (AWS): Launched in 2006, AWS started with Simple Storage Service (S3) and Elastic Compute Cloud (EC2). Since then, it has become huge in services, offering computing, storage, machine learning, and more.
  • Google Cloud Platform (GCP): Google jumped into the cloud market in 2008, leaning on its expertise in search. GCP offers in AI, machine learning, and big data services.
  • Microsoft Azure: Initially called Windows Azure (2008). Huge Surprise: (grin) this cloud platform gained traction by integrating seamlessly with Microsoft’s enterprise tools. Azure now competes strongly with AWS for enterprise business .

What Are Lambda, Cloud Functions, and Azure Functions?

AWS Lambda

AWS Lambda lets you run code without provisioning or managing servers. It supports multiple languages, executes in response to triggers (S3 events, API Gateway, etc.), and scales automatically.

Google Cloud Functions

Google Cloud Functions provide a fully managed, event-driven execution environment. They are deeply integrated with GCP services like Pub/Sub, Cloud Storage, and Firestore.

Azure Functions

Azure Functions offer a serverless compute service with deep integration into Microsoft’s ecosystem. They support both consumption-based pricing and premium plans for higher performance needs.

Similarities and Differences

FeatureAWS LambdaGoogle Cloud FunctionsAzure Functions
Trigger EventsS3, API Gateway, DynamoDBPub/Sub, Cloud StorageEvent Grid, Blob Storage
Supported LanguagesPython, C#, Node.js, Go, JavaPython, Node.js, Go, JavaPython, C#, Node.js, Java
Execution Time Limit15 minutes9 minutes5 minutes (consumption plan)
Cold Start PerformanceSlower due to container boot timeFasterVaries depending on plan
IntegrationAWS ecosystemGCP ecosystemMicrosoft ecosystem
Pricing ModelPay per execution timePay per execution timeConsumption-based, premium plans available

Common Problems They Solve

  • Running backend logic without managing servers
  • Handling API requests without a full-fledged backend
  • Processing files in storage (e.g., image processing, video encoding)
  • Handling real-time streaming data
  • Responding to database changes
  • Automating workflows

Code Samples

AWS Lambda

Python

1
2
3
4
5
6
7
import json

def lambda_handler(event, context):
    return {
        'statusCode': 200,
        'body': json.dumps('Hello from AWS Lambda!')
    }

C#

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
using System;
using Amazon.Lambda.Core;

[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))]

public class Function
{
    public string FunctionHandler(string input, ILambdaContext context)
    {
        return "Hello from AWS Lambda!";
    }
}

Google Cloud Functions

Python

1
2
def hello_world(request):
    return "Hello from Google Cloud Functions!", 200

C#

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
using Google.Cloud.Functions.Framework;
using Microsoft.AspNetCore.Http;
using System.Threading.Tasks;

public class Function : IHttpFunction
{
    public async Task HandleAsync(HttpContext context)
    {
        await context.Response.WriteAsync("Hello from Google Cloud Functions!");
    }
}

Azure Functions

Python

1
2
3
4
import azure.functions as func

def main(req: func.HttpRequest) -> func.HttpResponse:
    return func.HttpResponse("Hello from Azure Functions!")

C#

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
using System.IO;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using System.Threading.Tasks;

public static class Function
{
    [FunctionName("HelloWorld")]
    public static async Task<IActionResult> Run(
        [HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequest req)
    {
        return new OkObjectResult("Hello from Azure Functions!");
    }
}

Key Ideas Table

ConceptExplanation
AWS LambdaServerless compute on AWS
Google Cloud FunctionsServerless compute on GCP
Azure FunctionsServerless compute on Azure
Event-DrivenAll three execute based on triggers
Cold StartDelay when functions start after inactivity
PricingPay per execution model

References