Error waiting for Creating CloudFunctions Function: Error Code 3,

Viewed 561

Hello I am trying to create my Google Cloud Function in Python by using Terraform

resource "google_cloudfunctions_function" "function" {
    name        = "scheduled-cloud-function-python-api-request"
    description = "A Python Cloud Function that is triggered by a Cloud Schedule."
    runtime     = "python37"

    available_memory_mb   = 128
    source_archive_bucket = google_storage_bucket.bucket.name
    source_archive_object = google_storage_bucket_object.archive.name
    trigger_http          = true
    entry_point           = "http_handler" # This is the name of the function that will be executed in your Python code
}

And it's giving me an error at this code block after I do terraform apply:

Error code 3, message: Function failed on loading user code.

What am I doing wrong here?

This is my python code :

import requests
import csv

request = requests.get(f'https://api.sportsdata.io/v3/nba/scores/json/TeamSeasonStats/2022?key=')

nba_team_stats = request.json()
data_file = open('nba_team_stats.csv', 'w')
csv_writer = csv.writer(data_file)
count = 0

for stats in nba_team_stats:
    if count == 0:
        header = stats.keys()
        csv_writer.writerow(header)
        count += 1
    csv_writer.writerow(stats.values())
data_file.close()

Am I writing my Python Code in an undesired way for the GCP function to execute?

0 Answers
Related