Update deployment

Update a Game Server deployment.

Explore further

For detailed documentation that includes this code sample, see the following:

Code sample


To learn how to install and use the client library for Game Servers, see Game Servers client libraries.

using Google.Cloud.Gaming.V1;
using Google.LongRunning;
using Google.Protobuf.WellKnownTypes;
using System.Threading.Tasks;

public class UpdateDeploymentSample
    public async Task<GameServerDeployment> UpdateDeploymentAsync(
        string projectId, string deploymentId)
        // Create the client.
        GameServerDeploymentsServiceClient client = await GameServerDeploymentsServiceClient.CreateAsync();

        GameServerDeployment deployment = new GameServerDeployment
            GameServerDeploymentName = GameServerDeploymentName.FromProjectLocationDeployment(projectId, "global", deploymentId)
        deployment.Labels.Add("label-key-1", "label-value-1");
        deployment.Labels.Add("label-key-2", "label-value-2");

        UpdateGameServerDeploymentRequest request = new UpdateGameServerDeploymentRequest
            GameServerDeployment = deployment,
            UpdateMask = new FieldMask { Paths = { "labels" } }

        // Make the request.
        Operation<GameServerDeployment, OperationMetadata> response = await client.UpdateGameServerDeploymentAsync(request);
        Operation<GameServerDeployment, OperationMetadata> completedResponse = await response.PollUntilCompletedAsync();

        // Retrieve the operation result. This result will NOT contain the updated labels.
        // If you want to get the updated resource, use a GET request on the resource.
        return completedResponse.Result;


To learn how to install and use the client library for Game Servers, see Game Servers client libraries.

import (

	gaming "cloud.google.com/go/gaming/apiv1"
	gamingpb "google.golang.org/genproto/googleapis/cloud/gaming/v1"

// updateGameServerDeployment updates a game server deployment.
func updateGameServerDeployment(w io.Writer, projectID, deploymentID string) error {
	// projectID := "my-project"
	// deploymentID := "mydeployment"
	ctx := context.Background()
	client, err := gaming.NewGameServerDeploymentsClient(ctx)
	if err != nil {
		return fmt.Errorf("NewGameServerDeploymentsClient: %v", err)
	defer client.Close()

	req := &gamingpb.UpdateGameServerDeploymentRequest{
		GameServerDeployment: &gamingpb.GameServerDeployment{
			Name:        fmt.Sprintf("projects/%s/locations/global/gameServerDeployments/%s", projectID, deploymentID),
			Description: "My Updated Game Server Deployment",
			Labels: map[string]string{
				"label-key-1": "label-value-1",
		UpdateMask: &fieldmaskpb.FieldMask{
			Paths: []string{
				"description", "labels",

	op, err := client.UpdateGameServerDeployment(ctx, req)
	if err != nil {
		return fmt.Errorf("UpdateGameServerDeployment: %v", err)
	resp, err := op.Wait(ctx)
	if err != nil {
		return fmt.Errorf("Wait: %v", err)

	fmt.Fprintf(w, "Deployment updated: %v", resp.Name)
	return nil


To learn how to install and use the client library for Game Servers, see Game Servers client libraries.

import com.google.api.gax.longrunning.OperationFuture;
import com.google.cloud.gaming.v1.GameServerDeployment;
import com.google.cloud.gaming.v1.GameServerDeploymentsServiceClient;
import com.google.cloud.gaming.v1.OperationMetadata;
import com.google.protobuf.FieldMask;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class UpdateDeployment {
  public static void updateGameServerDeployment(String projectId, String deploymentId)
      throws IOException, InterruptedException, ExecutionException, TimeoutException {
    // String projectId = "your-project-id";
    // String deploymentId = "your-game-server-deployment-id";
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    try (GameServerDeploymentsServiceClient client = GameServerDeploymentsServiceClient.create()) {
      String deploymentName =
              "projects/%s/locations/global/gameServerDeployments/%s", projectId, deploymentId);

      GameServerDeployment deployment =
              .putLabels("key", "value")

      FieldMask fieldMask = FieldMask.newBuilder().addPaths("labels").build();

      OperationFuture<GameServerDeployment, OperationMetadata> call =
          client.updateGameServerDeploymentAsync(deployment, fieldMask);

      GameServerDeployment updated = call.get(1, TimeUnit.MINUTES);
      System.out.println("Game Server Deployment updated: " + updated.getName());


To learn how to install and use the client library for Game Servers, see Game Servers client libraries.

const {
} = require('@google-cloud/game-servers');

const client = new GameServerDeploymentsServiceClient();

async function updateGameServerDeployment() {
   * TODO(developer): Uncomment these variables before running the sample.
  // const projectId = 'Your Google Cloud Project ID';
  // const deploymentId = 'The unique ID for the Game Server Deployment';
  const request = {
    gameServerDeployment: {
      name: client.gameServerDeploymentPath(
      labels: {
        'label-key-1': 'label-value-1',
      description: 'My updated Game Server deployment',
    updateMask: {
      paths: ['labels', 'description'],

  const [operation] = await client.updateGameServerDeployment(request);
  const [result] = await operation.promise();

  console.log(`Deployment updated: ${result.name}`);



To learn how to install and use the client library for Game Servers, see Game Servers client libraries.

def update_deployment(project_id, deployment_id):
    """Updates a game server deployment."""

    client = gaming.GameServerDeploymentsServiceClient()

    # Location is hard coded as global, as game server deployments can
    # only be created in global.  This is done for all operations on
    # game server deployments, as well as for its child resource types.
    request = game_server_deployments.UpdateGameServerDeploymentRequest(
            labels={"label-key-1": "label-value-1", "label-key-2": "label-value-2"},

    operation = client.update_game_server_deployment(request)
    print(f"Update deployment operation: {operation.operation.name}")

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.