Cloud Functions용 커넥터

워크플로 내에서 Cloud Functions에 액세스하는 데 사용되는 기본 제공 함수를 정의하는 Workflows 커넥터입니다.

더 살펴보기

이 코드 샘플이 포함된 자세한 문서는 다음을 참조하세요.

코드 샘플

YAML

# This workflow demonstrates how to use the Cloud Functions connector:
# Create a function using source code stored as a zip archive in a
# Cloud Storage bucket (gs://BUCKET_NAME/cloud-function-source.zip)
# Source code must be a properly structured Cloud Function
# Expected output: "SUCCESS"
main:
  params: []
  steps:
    - init:
        assign:
          - project: ${sys.get_env("GOOGLE_CLOUD_PROJECT_ID")}
          - location: "us-central1"
          - name: "example-function"
          - bucket: "BUCKET_NAME"  # replace BUCKET_NAME placeholder
          - sourceArchiveUrl: ${"gs://" + bucket + "/cloud-function-source.zip"}
          - service_account: ${project + "@appspot.gserviceaccount.com"}  # App Engine default service account
    - create_function:
        call: googleapis.cloudfunctions.v1.projects.locations.functions.create
        args:
          location: ${"projects/" + project + "/locations/" + location}
          body:
            name: ${"projects/" + project + "/locations/" + location + "/functions/" + name}
            description: "Cloud Function for Workflows connector testing"
            entryPoint: "helloWorld"
            runtime: "nodejs10"
            serviceAccountEmail: ${service_account}
            sourceArchiveUrl: ${sourceArchiveUrl}
            httpsTrigger:
              securityLevel: "SECURE_OPTIONAL"
    - get_function:
        call: googleapis.cloudfunctions.v1.projects.locations.functions.get
        args:
          name: ${"projects/" + project + "/locations/" + location + "/functions/" + name}
        result: function
    - grant_permission_to_all:
        call: googleapis.cloudfunctions.v1.projects.locations.functions.setIamPolicy
        args:
          resource: ${"projects/" + project + "/locations/" + location + "/functions/" + name}
          body:
            policy:
              bindings:
                - members: ["allUsers"]
                  role: "roles/cloudfunctions.invoker"
    - call_function:
        call: http.get
        args:
          url: ${function.httpsTrigger.url}
        result: resp
    - verify_response:
        call: assert_response
        args:
          expected_response: "success"  # function must return "success" when triggered
          actual_response: ${resp.body}
    - delete_function:
        call: googleapis.cloudfunctions.v1.projects.locations.functions.delete
        args:
          name: ${"projects/" + project + "/locations/" + location + "/functions/" + name}
    - the_end:
        return: "SUCCESS"

assert_response:
  params: [expected_response, actual_response]
  steps:
    - compare:
        switch:
          - condition: ${expected_response == actual_response}
            next: end
    - fail:
        raise: ${"Expected response is " + expected_response + ". Received " + actual_response + " instead."}

다음 단계

다른 Google Cloud 제품의 코드 샘플을 검색하고 필터링하려면 Google Cloud 샘플 브라우저를 참조하세요.