cloudemu

Serverless

Functions-as-a-service — drive Lambda / Azure Functions / Cloud Functions with the real SDK

Serverless

Emulates FaaS: Lambda (AWS), Functions (Azure), Cloud Functions (GCP).

ProviderServiceSDK-compatDriver
AWSLambda (REST + JSON)✓ Liveaws.Lambda
AzureFunctions (Function Apps + /api/{name} invoke)✓ Liveazure.Functions
GCPCloud Functions v1 (Create LRO + :call)✓ Livegcp.CloudFunctions
import (
    "github.com/aws/aws-sdk-go-v2/service/lambda"
    lambdatypes "github.com/aws/aws-sdk-go-v2/service/lambda/types"
    awsserver "github.com/stackshy/cloudemu/server/aws"
)

cloud := cloudemu.NewAWS()
ts := httptest.NewServer(awsserver.New(awsserver.Drivers{Lambda: cloud.Lambda}))

client := lambda.NewFromConfig(cfg, func(o *lambda.Options) {
    o.BaseEndpoint = aws.String(ts.URL)
})

client.CreateFunction(ctx, &lambda.CreateFunctionInput{
    FunctionName: aws.String("my-handler"),
    Runtime:      lambdatypes.RuntimeGo1x,
    Role:         aws.String("arn:aws:iam::000000000000:role/test"),
    Handler:      aws.String("main"),
    Code:         &lambdatypes.FunctionCode{ZipFile: []byte("z")},
})

// Register a Go handler so Invoke has something to run.
cloud.Lambda.RegisterHandler("my-handler", func(ctx context.Context, payload []byte) ([]byte, error) {
    return []byte(`{"status":"ok"}`), nil
})

resp, _ := client.Invoke(ctx, &lambda.InvokeInput{
    FunctionName: aws.String("my-handler"),
    Payload:      []byte(`{"key":"value"}`),
})
fmt.Println(string(resp.Payload)) // {"status":"ok"}

Same shape with armappservice (Azure) and google.golang.org/api/cloudfunctions/v1 (GCP) — see SDK-Compat Server.

Operations supported via SDK-compat

Lambda: CreateFunction, GetFunction, ListFunctions, DeleteFunction, Invoke (sync).

Azure Functions: Microsoft.Web/sites CreateOrUpdate / Get / List / Delete + non-ARM /api/{name} invoke.

GCP Cloud Functions: Create (LRO), Get, List, Delete (LRO), :call (sync invoke), Operations.Get for LRO polling.

Alternative: Portable Go API

import sdriver "github.com/stackshy/cloudemu/serverless/driver"

aws.Lambda.CreateFunction(ctx, sdriver.FunctionConfig{
    Name: "my-handler", Runtime: "go1.x", Handler: "main",
})
aws.Lambda.RegisterHandler("my-handler", func(_ context.Context, p []byte) ([]byte, error) {
    return []byte(`{"ok":true}`), nil
})
out, _ := aws.Lambda.Invoke(ctx, sdriver.InvokeInput{
    FunctionName: "my-handler", Payload: []byte(`{}`),
})

The Portable API also exposes operations not yet on the SDK-compat surface: published versions, weighted aliases, layers, function concurrency, event source mappings.

On this page