This sample shows how to deploy asynchronous functions to Cloud Run functions with the Functions Framework. It includes examples for both HTTP and CloudEvent functions, which can be found in the main.py file.
Install the dependencies for this example:
pip install -r requirements.txtTo run the HTTP function locally, use the functions-framework command:
functions-framework --target=hello_async_httpThen, send a request to it from another terminal:
curl localhost:8080
# Output: Hello, async world!To run the CloudEvent function, specify the target and set the signature type:
functions-framework --target=hello_async_cloudevent --signature-type=cloudeventThen, in another terminal, send a sample CloudEvent using the provided script:
python send_cloud_event.pyYou can deploy these functions to Cloud Run using the gcloud CLI.
gcloud run deploy async-http-function \
--source . \
--function hello_async_http \
--base-image python312 \
--region <YOUR_REGION>gcloud run deploy async-cloudevent-function \
--source . \
--function hello_async_cloudevent \
--base-image python312 \
--region <YOUR_REGION>After deploying, you can invoke the CloudEvent function by sending an HTTP POST request with a CloudEvent payload to its URL.