Test Python Google Cloud Functions locally

后端 未结 4 1614
一个人的身影
一个人的身影 2021-02-01 04:24

I\'m trying out the Python3.7 runtime on Google Cloud Functions. I am able to deploy the functions and make them work once deployed, however, I can\'t seem to run the emulator t

4条回答
  •  青春惊慌失措
    2021-02-01 05:09

    Update

    Please, use the official emulator and serving framework from GCP https://github.com/GoogleCloudPlatform/functions-framework-python

    You can install it with

    pip install functions-framework
    

    Deprecated

    Based on Dustin's answer I've developed a package to serve as emulator:

    pip install gcp-functions-emulator
    

    Given you want to serve the following function

    # mycloudfunction.py
    def api(request):
      return 'important data'
    

    To emulate we have to call it like so:

    gcpfemu  
    

    For example, with the code above we will call it:

    gcpfemu mycloudfunction.py api
    

    And to access the data we can use for example curl:

    curl localhost:5000/api
    > important data
    

提交回复
热议问题