透過 HTTP 要求停止 Compute Engine 執行個體

在工作流程中提出已驗證的要求,使用 OAuth 2.0 停止 Compute Engine 執行個體。

程式碼範例

YAML

- initialize:
    assign:
      - project: ${sys.get_env("GOOGLE_CLOUD_PROJECT_NUMBER")}
      - zone: "us-central1-a"
      - vm_to_stop: "examplevm"
- stop_instance:
    call: http.post
    args:
      url: ${"https://compute.googleapis.com/compute/v1/projects/"+project+"/zones/"+zone+"/instances/"+vm_to_stop+"/stop"}
      auth:
        type: OAuth2
    result: stop_result

後續步驟

如要搜尋及篩選其他 Google Cloud 產品的程式碼範例,請參閱 Google Cloud 範例瀏覽器