iTranslated by AI
The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🔥
How to directly execute Google Cloud Functions
Conclusion
There are two main options:
- Execute "Test function" in the GCP console
- Run the gcloud command
*Note: This method is also applicable to functions deployed using Cloud Functions for Firebase.
Use Cases / Challenges
- You want to deploy a Cloud Functions function and execute it directly
- You want to call a one-off throwaway function
- You want to directly execute scheduled or HTTP call functions
Method via the GCP Console
- Log in with the desired account in the GCP console
- Enter the target project in the GCP console
- Switch to the desired environment in the GCP console
- Navigate to the Cloud Functions page
- Go to "Function details" by clicking the function name link
- Move to the "Testing" tab
- Execute "Test function"
Using the gcloud command
For more details, see the official documentation at the link.
gcloud functions call YOUR_FUNCTION_NAME --data '{"name":"Keyboard Cat"}'
Troubleshooting Errors
{"error":{"message":"Bad Request","status":"INVALID_ARGUMENT"}}
How to handle the above error when executing an http onCall function:
- Include a
dataelement in JSON format - Execute
*Note: Due to Cloud Functions specifications, this is required even if no data is actually needed.
{
"data": {
"hoge": 'Enter arbitrary data here',
"fuga": 'You must pass data with a "data" element in JSON format'
}
}
References
Discussion