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.
#############################################################

0 3 1,718
3 REPLIES 3

Hi @Prosenjit05,

Welcome to Google Cloud Community!

Based on the logs you provided, Google Cloud Buildpacks should meet the default generic builder listed in this documentation on buildpack builders. Python version should be at 3.11 at most.

Also, as suggested in the logs, please report any issues encountered through this Github issue link so that they could further take a look at this.

Hope this helps.

Hi Robert,

Thanks a lot for the reply on this.

As you mentioned the max version of Python should be 3.11, so I tried with 3.10 version, but still facing the issue. PFA the screenshot.

GCPErrorCapture1.PNG

Error in the console while running a test in the cloud function:

[6:01:24 PM] - Preparing function sources ...
[6:01:25 PM] - Building function sources ...
[6:01:27 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/16 12:31:27 [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/16 12:31:27 [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


#############################################################
[6:01:27 PM] - Error while building function sources. Please check logs.
#############################################################

I keep getting the same error.  My code runs locally.  It is something with the build packs and the documentation around resolving build pack issues is nearly nonexistent.