This sample shows how to deploy asynchronous functions to Cloud Run 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> \
--allow-unauthenticatedgcloud run deploy async-cloudevent-function \
--source . \
--function hello_async_cloudevent \
--base-image python312 \
--region <YOUR_REGION> \
--set-env-vars=FUNCTION_SIGNATURE_TYPE=cloudevent \
--allow-unauthenticatedAfter deploying, you can invoke the CloudEvent function by sending an HTTP POST request with a CloudEvent payload to its URL.