Reputation: 364
I have a GCF written in Python 3.7, I'm trying to get the trigger endpoint url from within the function itself.
I need the function to comunicate its url to other systems, programmatically.
Am I in luck? is there a way to achieve this?
Upvotes: 1
Views: 156
Reputation: 21520
Yes:
import os
def get_url(request):
return request.url_root + os.environ['X_GOOGLE_FUNCTION_NAME']
Upvotes: 1
Reputation: 8056
A possible solution would be to construct the url from the environ
dictionary:
def get_url(request):
env = request.__dict__['environ']
return "https://{}-{}.cloudfunctions.net/{}".format(env['X_GOOGLE_FUNCTION_REGION'], env['GCP_PROJECT'], env['X_GOOGLE_FUNCTION_NAME'])
Upvotes: 1