Cloud Functions for Firebase یک چارچوب بدون سرور است که به شما امکان میدهد به طور خودکار کد پشتیبان را در پاسخ به رویدادهایی که توسط رویدادهای پسزمینه، درخواستهای HTTPS، Admin SDK یا کارهای Cloud Scheduler ایجاد میشوند، اجرا کنید. کد جاوا اسکریپت، تایپ اسکریپت یا پایتون شما در زیرساخت Google Cloud ذخیره می شود و در یک محیط مدیریت شده اجرا می شود. نیازی به مدیریت و مقیاس بندی سرورهای خود نیست.
آیا قبلاً از عملکردهای ابری در Google Cloud استفاده می کنید؟ درباره نحوه قرار گرفتن Firebase در تصویر بیشتر بدانید .
با استفاده از Admin SDK همراه با توابع Cloud، در میان ویژگیهای Firebase یکپارچه شوید و با نوشتن وبکهوکهای خود، با سرویسهای شخص ثالث یکپارچه شوید. Cloud Functions کد دیگ بخار را به حداقل می رساند و استفاده از Firebase و Google Cloud را در داخل عملکرد شما آسان تر می کند.
تعمیر و نگهداری صفر
کد جاوا اسکریپت، تایپ اسکریپت یا پایتون خود را با یک فرمان از خط فرمان در سرورهای ما مستقر کنید. پس از آن، Firebase به طور خودکار منابع محاسباتی را برای مطابقت با الگوهای استفاده کاربران شما افزایش می دهد. شما هرگز در مورد اعتبار، پیکربندی سرور، تهیه سرورهای جدید یا از کار انداختن سرورهای قدیمی نگران نباشید.
منطق شما را خصوصی و امن نگه می دارد
در بسیاری از موارد، توسعه دهندگان ترجیح می دهند منطق برنامه را روی سرور کنترل کنند تا از دستکاری سمت کلاینت جلوگیری کنند. همچنین، گاهی اوقات مطلوب نیست که اجازه دهیم آن کد مهندسی معکوس شود. Cloud Functions کاملاً از مشتری عایق است، بنابراین می توانید مطمئن باشید که خصوصی است و همیشه دقیقاً همان کاری را که می خواهید انجام می دهد.
چگونه کار می کند؟
پس از نوشتن و استقرار یک تابع، سرورهای Google بلافاصله شروع به مدیریت عملکرد می کنند. میتوانید عملکرد را مستقیماً با یک درخواست HTTP، Admin SDK یا یک کار زمانبندیشده فعال کنید، یا در مورد توابع پسزمینه، سرورهای Google به رویدادها گوش میدهند و عملکرد را هنگام راهاندازی اجرا میکنند.
با افزایش یا کاهش بار، Google با مقیاس سریع تعداد نمونه های سرور مجازی مورد نیاز برای اجرای عملکرد شما پاسخ می دهد. هر تابع به صورت مجزا، در محیط خود با پیکربندی خاص خود اجرا می شود.
چرخه حیات یک تابع پس زمینه
شما برای یک تابع جدید کد می نویسید، یک ارائه دهنده رویداد (مانند Cloud Firestore ) را انتخاب می کنید و شرایطی را که تابع باید تحت آن اجرا شود، تعریف می کنید.
وقتی تابع خود را مستقر می کنید:
Firebase CLI یک بایگانی .zip از کد تابع ایجاد می کند، که سپس قبل از اینکه Cloud Functions یک مخزن Artifact Registry (به نام gcf-artifacts ) در پروژه شما ایجاد کند، در یک سطل Cloud Storage (با پیشوند با gcf-sources ) آپلود می شود.
Cloud Build کد تابع را بازیابی می کند و منبع تابع را می سازد. میتوانید گزارشهای Cloud Build را در کنسول Google Cloud مشاهده کنید.
تصویر محفظه برای کد توابع ساخته شده در یک مخزن خصوصی Artifact Registry در پروژه شما (به نام gcf-artifacts ) آپلود می شود و عملکرد جدید شما منتشر می شود.
هنگامی که ارائه دهنده رویداد رویدادی را ایجاد می کند که با شرایط تابع مطابقت دارد، کد فراخوانی می شود. این تابع دارای یک حساب سرویس متصل به آن است که می تواند برای دسترسی به سایر خدمات Firebase با کمک Firebase Admin SDK استفاده شود.
اگر عملکرد مشغول رسیدگی به بسیاری از رویدادها باشد، Google نمونههای بیشتری ایجاد میکند تا کار را سریعتر انجام دهد. اگر عملکرد بیکار باشد، نمونه ها پاک می شوند.
هنگامی که عملکرد را با استقرار کدهای بهروز شده بهروزرسانی میکنید، نمونههای نسخههای قدیمیتر به همراه مصنوعات ساخت در Artifact Registry پاک میشوند و با نمونههای جدید جایگزین میشوند.
وقتی این تابع را حذف میکنید، تمام نمونهها و بایگانیهای فشرده، همراه با مصنوعات ساخت مرتبط در Artifact Registry پاک میشوند. ارتباط بین عملکرد و ارائه دهنده رویداد حذف می شود.
علاوه بر گوش دادن به رویدادها با یک تابع پسزمینه، میتوانید مستقیماً با یک درخواست HTTP یا تماسی از مشتری، عملکردها را فراخوانی کنید. همچنین میتوانید عملکردها را در یک برنامه زمانبندی ثابت راهاندازی کنید یا عملکردهای وظیفه را از طریق Admin SDK در صف قرار دهید.
مسیر پیاده سازی
Cloud Functions تنظیم کنید
Firebase CLI را نصب کنید و Cloud Functions در پروژه Firebase خود راه اندازی کنید.
توابع را بنویسید
کد جاوا اسکریپت، کد تایپ اسکریپت یا کد پایتون را برای مدیریت رویدادها از سرویسهای Firebase، سرویسهای Google Cloud یا سایر ارائهدهندگان رویداد بنویسید.
تاریخ آخرین بهروزرسانی 2025-08-15 بهوقت ساعت هماهنگ جهانی.
[[["درک آسان","easyToUnderstand","thumb-up"],["مشکلم را برطرف کرد","solvedMyProblem","thumb-up"],["غیره","otherUp","thumb-up"]],[["اطلاعاتی که نیاز دارم وجود ندارد","missingTheInformationINeed","thumb-down"],["بیشازحد پیچیده/ مراحل بسیار زیاد","tooComplicatedTooManySteps","thumb-down"],["قدیمی","outOfDate","thumb-down"],["مشکل ترجمه","translationIssue","thumb-down"],["مشکل کد / نمونهها","samplesCodeIssue","thumb-down"],["غیره","otherDown","thumb-down"]],["تاریخ آخرین بهروزرسانی 2025-08-15 بهوقت ساعت هماهنگ جهانی."],[],[],null,["Cloud Functions for Firebase \nplat_ios plat_android plat_web plat_flutter plat_cpp plat_unity \nCloud Functions for Firebase is a serverless framework that lets you automatically run backend code in response to events triggered by background events, HTTPS requests, the Admin SDK, or Cloud Scheduler jobs. Your JavaScript, TypeScript or Python code is stored on Google Cloud infrastructure and runs in a managed environment. There's no need to manage and scale your own servers.\n\n\u003cbr /\u003e\n\nAlready using Cloud Functions in Google Cloud?\n[Learn more](/docs/functions/functions-and-firebase) about how Firebase fits\ninto the picture.\n\n[Get started](/docs/functions/get-started)\n[Use cases](/docs/functions/use-cases)\n\nKey capabilities\n\n|----------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| Integrates Firebase features and connects Firebase with Google Cloud | The functions you write can respond to events generated by various Firebase and Google Cloud features, from [Firebase Authentication triggers](/docs/functions/auth-events) to [Cloud Storage Triggers](/docs/functions/gcp-storage-events). Integrate across Firebase features using the [Admin SDK](/docs/admin/setup) together with Cloud Functions, and integrate with third-party services by writing your own webhooks. Cloud Functions minimizes boilerplate code, making it easier to use Firebase and Google Cloud inside your function. |\n| Zero maintenance | Deploy your JavaScript, TypeScript, or Python code to our servers with one command from the command line. After that, Firebase automatically scales up computing resources to match the usage patterns of your users. You never worry about credentials, server configuration, provisioning new servers, or decommissioning old ones. |\n| Keeps your logic private and secure | In many cases, developers prefer to control application logic on the server to avoid tampering on the client side. Also, sometimes it's not desirable to allow that code to be reverse engineered. Cloud Functions is fully insulated from the client, so you can be sure it is private and always does exactly what you want. |\n\nHow does it work?\n\nAfter you write and deploy a function, Google's servers begin to manage the\nfunction immediately. You can fire the function directly with an HTTP request,\nthe Admin SDK, or a scheduled job, or, in the case of background functions,\nGoogle's servers listen for events and run the function when it is\ntriggered.\n\nAs the load increases or\ndecreases, Google responds by rapidly scaling the number of virtual server\ninstances needed to run your function. Each function runs in isolation, in its\nown environment with its own configuration.\n\nLifecycle of a background function\n\n1. You write code for a new function, selecting an event provider (such as Cloud Firestore), and defining the conditions under which the function should execute.\n2. When you deploy your function:\n 1. The Firebase CLI creates a `.zip` archive of the function code, which is then uploaded to a Cloud Storage bucket (prefixed with `gcf-sources`) before Cloud Functions creates an Artifact Registry repository (named `gcf-artifacts`) in your project.\n 2. Cloud Build retrieves the function code and builds the function source. You can view Cloud Build logs in the [Google Cloud console](//console.cloud.google.com/logs/query;query%3Dresource.type%253D%2522build%2522&sa=D&ust=1597179510979000&usg=AFQjCNG2BmFrgWjGoP83WiMrB2TLLXpBEQ).\n 3. The container image for the built functions code is uploaded to a private Artifact Registry repository in your project (named `gcf-artifacts`), and your new function is rolled out.\n3. When the event provider generates an event that matches the function's conditions, the code is invoked. The function has a service account attached to it that can be used to access other Firebase services with the help of the Firebase Admin SDK.\n4. If the function is busy handling many events, Google creates more instances to handle work faster. If the function is idle, instances are cleaned up.\n5. When you update the function by deploying updated code, instances for older versions are cleaned up along with build artifacts in Artifact Registry, and replaced by new instances.\n6. When you delete the function, all instances and zip archives are cleaned up, along with related build artifacts in Artifact Registry. The connection between the function and the event provider is removed.\n\nIn addition to listening for events with a background function, you can call\nfunctions directly with an HTTP request or a\n[call from the client](/docs/functions/callable). You can also trigger functions\non a fixed [schedule](/docs/functions/schedule-functions) or\n[enqueue task functions](/docs/functions/task-functions) via the Admin SDK.\n\nImplementation path\n\n|---|------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| | Set up Cloud Functions | Install the Firebase CLI and initialize Cloud Functions in your Firebase project. |\n| | Write functions | Write JavaScript code, TypeScript code, or Python code to handle events from Firebase services, Google Cloud services, or other event providers. |\n| | Test functions | Use the [local emulator](/docs/functions/local-emulator) to test your functions. |\n| | Deploy and monitor | Upgrade your project to the [pay-as-you-go Blaze pricing plan](/pricing) and deploy your functions using the Firebase CLI. You can then use the [Google Cloud console](//console.cloud.google.com/functions/list) to view and search through your logs. |\n\nNext steps\n\n- [Get started](/docs/functions/get-started) setting up, creating, and deploying functions.\n- Learn more about [what you can do with functions](/docs/functions/use-cases).\n- Try the [Cloud Functions codelab](https://codelabs.developers.google.com/codelabs/firebase-cloud-functions/#0)."]]