Thanks @apeltop for responding.
No joy with that im afraid.
I was curious if this relates to ‘CPU:RAM’ ratio when >4gb…but maybe not, im just guessing at this point.
(below is the same for 4096M variants, but anything <4096 is good/success)
# 8192MB
googleapiclient.errors.HttpError: <HttpError 400 when requesting [https://cloudfunctions.googleapis.com/v2/projects/myproj/locations/europe-west2/functions/my-function?alt=json ](https://cloudfunctions.googleapis.com/v2/projects/myproj/locations/europe-west2/functions/my-function?alt=json)
returned "Invalid Request. Violations: Invalid memory allocation 8192MB specified for 1st Gen function.". Details: "Invalid Request. Violations: Invalid memory allocation 8192MB specified for 1st Gen function.">
# 8192MiB
Same as above
# 8192M
googleapiclient.errors.HttpError: <HttpError 400 when requesting [https://cloudfunctions.googleapis.com/v2/projects/myproj/locations/europe-west2/functions/my-function?alt=json ](https://cloudfunctions.googleapis.com/v2/projects/myproj/locations/europe-west2/functions/my-function?alt=json)
returned "Failed to update 1st Gen function projects/myproj/locations/europe-west2/functions/my-function: memory_mb: Invalid memory allocation. Should be one of: [128, 256, 512, 1024, 2048, 4096, 8192]".
# 8192Mi
PATCH is accepted, but after deployment completes, the function has 256M
Script to repro:
#!/usr/bin/env python3
"""-------------------------------------------------------------------------------------------------------
pip install google-api-python-client
python test_gen1_via_v2_api.py
-------------------------------------------------------------------------------------------------------"""
from googleapiclient.discovery import build as gcp_apis_client
def get_cloud_function_client(api_version: str) -> gcp_apis_client:
"""
Return GCP API client, cloudfunctions
:return: cloudfunctions client
"""
cloudfunction_client: gcp_apis_client = gcp_apis_client("cloudfunctions",
api_version)
return cloudfunction_client
def get_cloud_function(cloud_function_client: gcp_apis_client,
cloud_function_name: str,
cloud_function_region: str,
cloud_function_project: str) -> dict:
"""
GET a cloud function.
:param gcp_apis_client cloud_function_client: An instance of the cloudfunctions python API client/wrapper
:param str cloud_function_name: The name of the cloud function
:param str cloud_function_region: The region the cloud function is hosted in
:param str cloud_function_project: The GCP project the cloud function is hosted in
:return: The json object of the cloud function
"""
current_cloud_function_details = cloud_function_client.projects().locations().functions().get(
name="projects/%s/locations/%s/functions/%s" % (cloud_function_project,
cloud_function_region,
cloud_function_name)).execute()
return current_cloud_function_details
def patch_cloud_function(cloud_function_client: gcp_apis_client,
cloud_function_name: str,
cloud_function_region: str,
cloud_function_project: str,
current_cloud_function_details: dict) -> dict:
"""
Method to PATCH a cloud function to trigger a redeployment of it.
:param gcp_apis_client cloud_function_client: An instance of the cloudfunctions python API client/wrapper
:param str cloud_function_name: The name of the cloud function
:param str cloud_function_region: The region the cloud function is hosted in
:param str cloud_function_project: The GCP project the cloud function is hosted in
:param dict current_cloud_function_details: The current cloud function details
:return: The response
"""
patched_resp = cloud_function_client.projects().locations().functions().patch(
name="projects/%s/locations/%s/functions/%s" % (cloud_function_project,
cloud_function_region,
cloud_function_name),
body=current_cloud_function_details).execute()
return patched_resp
def main():
"""
PATCH gen1 cloud function, via v2 API, using different memory's
"""
# TODO: First, manually deploy a gen1 cloud function(python runtime in this example).
# Client
cloud_function_client = get_cloud_function_client(api_version="v2")
# GET current cloud function
cloud_function_name = "my-function"
cloud_function_region = "europe-west2"
cloud_function_project = "myproj"
current_cloud_function = get_cloud_function(cloud_function_client,
cloud_function_name,
cloud_function_region,
cloud_function_project)
# Update memory
current_cloud_function["serviceConfig"]["availableMemory"] = "8192MB" # Failure
# current_cloud_function["serviceConfig"]["availableMemory"] = "8192M" # Failure
# current_cloud_function["serviceConfig"]["availableMemory"] = "8192Mi" # Accepted, but deploys as 256M
# current_cloud_function["serviceConfig"]["availableMemory"] = "8192MiB" # Failure
# current_cloud_function["serviceConfig"]["availableMemory"] = "4096MB" # Failure
# current_cloud_function["serviceConfig"]["availableMemory"] = "4096M" # Failure
# current_cloud_function["serviceConfig"]["availableMemory"] = "4096Mi" # Accepted, but deploys as 256M
# current_cloud_function["serviceConfig"]["availableMemory"] = "4096MiB" # Failure
# current_cloud_function["serviceConfig"]["availableMemory"] = "2048M" # Success
# current_cloud_function["serviceConfig"]["availableMemory"] = "1024M" # Success
# current_cloud_function["serviceConfig"]["availableMemory"] = "512M" # Success
# current_cloud_function["serviceConfig"]["availableMemory"] = "256M" # Success
# current_cloud_function["serviceConfig"]["availableMemory"] = "128M" # Success
# PATCH
patched_resp = patch_cloud_function(cloud_function_client,
cloud_function_name,
cloud_function_region,
cloud_function_project,
current_cloud_function)
print(patched_resp)
if __name__ == "__main__":
main()
V2 API cloud functions object
{
'name': 'projects/myproj/locations/europe-west2/functions/my-function',
'buildConfig': {
'build': 'projects/my-proj-number/locations/europe-west2/builds/redacted',
'runtime': 'python312',
'entryPoint': 'test_entrypoint',
'source': {
'storageSource': {
'bucket': 'my-bucket',
'object': 'cloud_function_zips/my-function.zip'
}
},
'dockerRegistry': 'ARTIFACT_REGISTRY',
'automaticUpdatePolicy': {}
},
'serviceConfig': {
'timeoutSeconds': 60,
'maxInstanceCount': 3000,
'ingressSettings': 'ALLOW_ALL',
'uri': 'https://europe-west2-myprof.cloudfunctions.net/my-function',
'serviceAccountEmail': 'myproj@appspot.gserviceaccount.com',
'availableMemory': '2048M',
'revision': '48',
'maxInstanceRequestConcurrency': 1,
'securityLevel': 'SECURE_ALWAYS'
},
'state': 'ACTIVE',
'updateTime': '2024-05-28T17:36:33.712275837Z',
'labels': {
'deployment-tool': 'cli-gcloud',
},
'environment': 'GEN_1',
'url': 'https://europe-west2-myproj.cloudfunctions.net/my-function'
}
V1 cloud functions object
{
'name': 'projects/myproj/locations/europe-west2/functions/my-function',
'sourceArchiveUrl': 'gs://my-bucket/cloud_function_zips/my-function.zip',
'httpsTrigger': {
'url': 'https://europe-west2-myproj.cloudfunctions.net/my-function',
'securityLevel': 'SECURE_ALWAYS'
},
'status': 'ACTIVE',
'entryPoint': 'test_entrypoint',
'timeout': '60s',
'availableMemoryMb': 2048,
'serviceAccountEmail': 'myproj@appspot.gserviceaccount.com',
'updateTime': '2024-05-28T17:36:22.291Z',
'versionId': '48',
'labels': {
'deployment-tool': 'cli-gcloud'
},
'runtime': 'python312',
'maxInstances': 3000,
'ingressSettings': 'ALLOW_ALL',
'buildId': 'redacted',
'buildName': 'projects/my-proj-number/locations/europe-west2/builds/redacted',
'dockerRegistry': 'ARTIFACT_REGISTRY',
'automaticUpdatePolicy': {}
}