Python Cloud Functions: gcloud functions deploy Change Name Different From Source Code

Jun 4, 2019
or Change Source File

Default

Usually we use this command

gcloud functions deploy test_hello_world --runtime python37 --trigger-http --project PROJECT_ID

To deploy a function named test_hello_world in the file main.py

def test_hello_world(request):    return 'Hello World'

Where you url for the function is

https://us-central1-PROJECT_ID.cloudfunctions.net/test_hello_world

Change Cloud Function Name

To change the cloud function name (different from source code function name)

gcloud functions deploy test --entry-point test_hello_world --runtime python37 --trigger-http --project travelopyz

Function name must contain only lower case Latin letters, digits and a hyphen (-). It must start with letter, must not end with a hyphen, and must be at most 63 characters long.

NOTE: It is not possible to group function name under subdirectory, such as /intents/test. An alternative would be via cloud functions url redirect via Cloud Functions Custom Domain With Firebase Hosting.

The generated url shall be

https://us-central1-PROJECT_ID.cloudfunctions.net/test

Change Source File

Sadly, the function must reside within the file named main.py, but you can change the directory name.

gcloud functions deploy test --entry-point test_hello_world --source production --runtime python37 --trigger-http --project travelopyz

--source=SOURCE Location of source code to deploy. Location of the source can be one of the following three options:

Source code in Google Cloud Storage (must be a .zip archive), Reference to source repository or, Local filesystem path (root directory of function source).

Create the file production/main.py.

References:

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.