#Publish Functions
Publish a Function by first configuring a Sandbox Service with public ingress and a restartable runtime, then creating a function from that service.
Configure a Publishable Service#
/api/v1/sandboxes/{id}/services
The update replaces the full service list. Include every service that should remain active on the sandbox.
goresp, err := sandbox.UpdateServices(ctx, []apispec.SandboxAppService{ { ID: "api", Port: 8080, Runtime: apispec.NewOptSandboxAppServiceRuntime(apispec.SandboxAppServiceRuntime{ Type: apispec.SandboxAppServiceRuntimeTypeCmd, Command: []string{"python3", "-m", "http.server", "8080", "--bind", "0.0.0.0", "-d", "/workspace/public"}, Cwd: apispec.NewOptString("/workspace"), }), Ingress: apispec.SandboxAppServiceIngress{ Public: true, Routes: []apispec.SandboxAppServiceRoute{ { ID: "api", PathPrefix: apispec.NewOptString("/"), Methods: []string{"GET"}, Resume: true, }, }, }, HealthCheck: apispec.NewOptSandboxAppServiceHealth(apispec.SandboxAppServiceHealth{ Path: apispec.NewOptString("/"), }), }, }) if err != nil { log.Fatal(err) } fmt.Printf("services: %d\n", len(resp.Services))
Check Publishability#
/api/v1/sandboxes/{id}/services
The response includes publishable and publish_blockers for every service. A service must be publishable before it can become a function revision.
goresp, err := sandbox.GetServices(ctx) if err != nil { log.Fatal(err) } for _, service := range resp.Services { fmt.Printf("%s publishable=%t blockers=%v\n", service.ID, service.Publishable, service.PublishBlockers) }
Create a Function#
/api/v1/functions
Creating a function creates the stable function record, revision 1, and the production alias.
goresult, err := client.CreateFunctionFromSandbox( ctx, sandbox.ID, "api", sandbox0.WithFunctionName("my-api"), ) if err != nil { log.Fatal(err) } fmt.Printf("function URL: %s\n", result.Function.URL)
Invoke the Function#
Use the returned url as the stable public endpoint.
bashcurl "$FUNCTION_URL/"
Next Steps#
Revisions And Aliases
Publish and promote new versions without changing the function URL.
Sandbox Services
Configure route auth, CORS, rate limits, rewrite rules, and timeouts.