Cloud Run

gRPC · port 8093

Configuration

No env var. Cloud Run has no official *_EMULATOR_HOST environment variable. You must configure the endpoint manually in your client code.

Go SDK example

Connect to localgcp, create a service, inspect it, list services, and delete it:

package main

import (
    "context"
    "fmt"
    "log"

    run "cloud.google.com/go/run/apiv2"
    runpb "cloud.google.com/go/run/apiv2/runpb"
    "google.golang.org/api/option"
    "google.golang.org/grpc"
    "google.golang.org/grpc/credentials/insecure"
)

func main() {
    ctx := context.Background()

    // Connect to localgcp (no TLS, no auth)
    client, err := run.NewServicesClient(ctx,
        option.WithEndpoint("localhost:8093"),
        option.WithoutAuthentication(),
        option.WithGRPCDialOption(grpc.WithTransportCredentials(
            insecure.NewCredentials(),
        )),
    )
    if err != nil {
        log.Fatal(err)
    }
    defer client.Close()

    parent := "projects/my-project/locations/us-central1"

    // Create a service (returns a long-running operation)
    // In localgcp the operation completes immediately -- no polling needed
    op, err := client.CreateService(ctx, &runpb.CreateServiceRequest{
        Parent:    parent,
        ServiceId: "my-service",
        Service:   &runpb.Service{},
    })
    if err != nil {
        log.Fatal(err)
    }
    svc, err := op.Wait(ctx)
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("Created: %s\n", svc.Name)

    // Get the service
    svc, err = client.GetService(ctx, &runpb.GetServiceRequest{
        Name: parent + "/services/my-service",
    })
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("URI: %s\n", svc.Uri)

    // List services
    iter := client.ListServices(ctx, &runpb.ListServicesRequest{
        Parent: parent,
    })
    for {
        s, err := iter.Next()
        if err != nil {
            break
        }
        fmt.Printf("Service: %s\n", s.Name)
    }

    // Delete the service
    delOp, err := client.DeleteService(ctx, &runpb.DeleteServiceRequest{
        Name: parent + "/services/my-service",
    })
    if err != nil {
        log.Fatal(err)
    }
    _, err = delOp.Wait(ctx)
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println("Deleted.")
}

Features

Not yet supported