简体   繁体   中英

how to initially we can invoke cloud function from deployment manager?

Question 1. I'm trying to create a cloud function through a cloud deployment manager. Once that is deployed, the function is unable to invoke initially. after testing or clicking a URL, the function is invoking.

Deployment.jinja

{% set deployment_name =  env["deployment"]  %}
{% set project = env['project']  %}
{% set region = "us-central1" %}

resources:
- type: storage.v1.bucket
  name: {{ deployment_name }}
  properties:
    project: {{ project }}
- name: CloudFunction
  type:  gcp-types/cloudfunctions-v1:projects.locations.functions
  properties:
    parent: projects/{{ project }}/locations/us-central1
    function: {{ deployment_name }}
    entryPoint: handler
    timeout: 60s
    availableMemoryMb: 256
    runtime: python39
    location: {{ region }}
    sourceArchiveUrl: gs://bucket/archive.zip
    httpsTrigger:
      url: https://{{ region }}-{{ project }}.cloudfunctions.net/{{ deployment_name }}
    environmentVariables:
      BUCKET: {{ deployment_name }}
      FUNCTION_REGION: {{ region }}
      PROJECT: {{ project }}

Question 2. Can we invoke a function based on CreateFunction or DeleteFunction? Same, how we call in AWS lambda like requestType=Create and requestType=Delete.

stack driver logs Ex: methodName: google.cloud.functions.v1.CloudFunctionsService.DeleteFunction and methodName: google.cloud.functions.v1.CloudFunctionsService.CreateFunction

simmillar like this:
def hello_world(request):
    if request['methodName']=="DeleteFunction":
       print("delete bucket")
    if request['methodName']=="CreateFunction":
       print("create bucket")
    

According to this Document: https://cloud.google.com/functions/docs/reference/rest/v1/projects.locations.functions/call

Need to use the below type:

cloudfunctions-v1:cloudfunctions.projects.locations.functions.call
- name: function-call
  type: gcp-types/cloudfunctions-v1:cloudfunctions.projects.locations.functions.call
  properties:
    name: "$(ref.CloudFunction.name)"
    data: '{"test":"test"}'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM