Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

GCP Cloud Function Error: Error while building function sources.

Hi,

I want to create a cloud function which would be triggered by a Billing Pub/Sub to stop the billing account when my budget is hit. While running the test for the cloud function written in Python 3.12, I am getting the below error in the console of the cloud function. Please guide.

========== The Function in Python 3.12:

import requests

def disable_billing(project_id):
    """Disables billing for a project."""

    headers = {"Authorization": "Bearer {}".format(os.environ["GOOGLE_APPLICATION_CREDENTIALS"])}
    response = requests.put(url, headers=headers, json={"billingEnabled": False})
    if response.status_code != 200:
        raise Exception("Failed to disable billing for project {}: {}".format(project_id, response.content))

def main(event, context):
    """Triggered by a Pub/Sub event."""

    print("Hello World")
    project_id = event["resource"]["name"]
    disable_billing(project_id)


 

========== Console Log Below:

[3:11:17 PM] - Preparing function sources ...
[3:11:18 PM] - Building function sources ...
[3:13:17 PM] - Error: Command failed: cd /gcf-working-dir/function-sources && pack build gcf-ui-function --builder gcr.io/gae-runtimes/buildpacks/python/builder --pull-policy if-not-present --env GOOGLE_FUNCTION_TARGET=main --env GOOGLE_FUNCTION_SIGNATURE_TYPE=cloudevent --env GOOGLE_DEVMODE=1 --env GOOGLE_RUNTIME_VERSION=3.12
[builder] === Python - Runtime (google.python.runtime@0.9.1) ===
[builder] layers path: /layers/google.python.runtime/python
[builder] Using Python version from GOOGLE_RUNTIME_VERSION: 3.12
[builder] 2023/12/09 09:43:17 [DEBUG] GET https://dl.google.com/runtimes/ubuntu1804/python/version.json
[builder] Failure: (ID: afc8608d) invalid Python version specified: failed to resolve version matching: 3.12
[builder] --------------------------------------------------------------------------------
[builder] Sorry your project couldn't be built.
[builder] Our documentation explains ways to configure Buildpacks to better recognise your project:
[builder] -> https://cloud.google.com/docs/buildpacks/overview
[builder] If you think you've found an issue, please report it:
[builder] -> https://github.com/GoogleCloudPlatform/buildpacks/issues/new
[builder] --------------------------------------------------------------------------------
ERROR: failed to build: executing lifecycle. This may be the result of using an untrusted builder: failed with status code: 51

at checkExecSyncError (node:child_process:826:11)
at execSync (node:child_process:900:15)
at buildFunction (/app/app.runfiles/google3/cloud/console/web/functions/external/testing_server/workers/build_function_worker.js:17:38)
at Object.<anonymous> (/app/app.runfiles/google3/cloud/console/web/functions/external/testing_server/workers/build_function_worker.js:35:131)
at Module._compile (node:internal/modules/cjs/loader:1095:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1124:10)
at Module.load (node:internal/modules/cjs/loader:975:32)
at Function.Module._load (node:internal/modules/cjs/loader:816:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12)
at MessagePort.<anonymous> (node:internal/main/worker_thread:183:24)
[builder] === Python - Runtime (google.python.runtime@0.9.1) ===
[builder] layers path: /layers/google.python.runtime/python
[builder] Using Python version from GOOGLE_RUNTIME_VERSION: 3.12
[builder] 2023/12/09 09:43:17 [DEBUG] GET https://dl.google.com/runtimes/ubuntu1804/python/version.json
[builder] Failure: (ID: afc8608d) invalid Python version specified: failed to resolve version matching: 3.12
[builder] --------------------------------------------------------------------------------
[builder] Sorry your project couldn't be built.
[builder] Our documentation explains ways to configure Buildpacks to better recognise your project:
[builder] -> https://cloud.google.com/docs/buildpacks/overview
[builder] If you think you've found an issue, please report it:
[builder] -> https://github.com/GoogleCloudPlatform/buildpacks/issues/new
[builder] --------------------------------------------------------------------------------
ERROR: failed to build: executing lifecycle. This may be the result of using an untrusted builder: failed with status code: 51


#############################################################
[3:13:18 PM] - Error while building function sources. Please check logs.
#############################################################

1 5 5,155
5 REPLIES 5