Aller au contenu

Cloud Functions

cloudFunctions:
- name: process-image
source: ./functions/process-image
entryPoint: handler
runtime: nodejs20
trigger: http
memory: 512M # formats GCP : 128M, 256M, 512M, 1024M, 2G...
cpu: "0.5"
timeout: 120 # secondes (number)
project: ${PROJECT_ID:-}
location: europe-west1
ChampTypeRequisDefautDescription
namestringouiNom de la function
sourcestringouiChemin vers le code source
entryPointstringnonmainPoint d’entree
runtimestringnonnodejs22Runtime (voir section ci-dessous)
triggerstringnonhttpType de trigger (http, pubsub)
trigger_topicstringsi pubsubTopic pour le trigger pubsub
memorystringnon256MMemoire allouee (mappee sur available_memory Cloud Run v2)
cpustringnon0.1CPU alloue (mappe sur available_cpu Cloud Run v2)
timeoutstringnon60Timeout d’execution (secondes)
max_instance_countnumbernon1Nombre max d’instances
min_instance_countnumbernon1Nombre min d’instances
max_instance_request_concurrencynumbernon1 (default GCP)Requetes concurrentes max par instance (max 1000, necessite cpu >= 1 pour > 1)
projectstringnonprojet courantProjet GCP
locationstringnoneurope-west1Region GCP
ingress_settingsstringnonALLOW_ALLFige a ALLOW_ALL cote Terraform (non surcharge actuellement)
descriptionstringnonDescription de la function
envVarsobject[]non[]Variables d’environnement
buildEnvVarsobject[]non[]Variables d’env pour le build
allUsers_invokerbooleannonfalseNon applique actuellement (bloc IAM desactive)
LangageVersions recommandeesLegacy (EOL cote editeur)
Node.jsnodejs22 (LTS), nodejs20nodejs10, nodejs12, nodejs14, nodejs16, nodejs18
Pythonpython313, python312, python311python37, python38, python39, python310
Gogo124, go123, go122, go121go113, go116, go118, go119, go120
Javajava21, java17java11
PHPphp83, php82php74, php81
Rubyruby34, ruby33, ruby32ruby27, ruby30
.NETdotnet8dotnet3, dotnet6

Les runtimes EOL sont toleres par le validator (retro-compatibilite), mais GCP peut refuser le deploiement. Utiliser les versions recommandees en priorite.

  • memory : 128M, 256M, 512M, 1024M, 2G, 4G, 8G, 16G, 32G (suffixes M ou G)
  • cpu : string numerique "0.08" a "8" (ex. "0.5", "1", "2"). Les valeurs hautes necessitent plus de memoire
  • timeout : nombre de secondes (1 a 3600 pour HTTP, 1 a 540 pour event-driven)
cloudFunctions:
- name: high-throughput
source: ./functions/heavy
runtime: nodejs20
memory: 1024M
cpu: "1"
min_instance_count: 1
max_instance_count: 10
max_instance_request_concurrency: 50 # 50 requetes concurrentes max par instance

max_instance_request_concurrency est utile quand la fonction peut traiter plusieurs requetes en parallele (I/O-bound). Par defaut, Cloud Functions v2 limite a 1 requete par instance — chaque nouvelle requete peut declencher un scale-up. Passer a 50-80 reduit cold starts et cout pour des workloads I/O-bound. Necessite cpu >= 1.

cloudFunctions:
- name: on-order-created
source: ./functions/on-order
entryPoint: onOrderCreated
runtime: nodejs20
trigger: pubsub
trigger_topic: order-events # Reference un topic declare dans topics.app ou topics.ext

Le trigger_topic est automatiquement resolu vers le nom reel du topic GCP.


Voir aussi : Toutes les proprietes