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).
| Provider | Service | SDK-compat | Driver |
|---|---|---|---|
| AWS | Lambda (REST + JSON) | ✓ Live | aws.Lambda |
| Azure | Functions (Function Apps + /api/{name} invoke) | ✓ Live | azure.Functions |
| GCP | Cloud Functions v1 (Create LRO + :call) | ✓ Live | gcp.CloudFunctions |
Use the real SDK (recommended)
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.