컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
Firebase용 Cloud Functions
plat_ios
plat_android
plat_web
plat_flutter
plat_cpp
plat_unity
Firebase용
Cloud Functions는 백그라운드 이벤트, HTTPS 요청,
Admin SDK 또는
Cloud Scheduler 작업에 의해 트리거되는 이벤트에 응답하여 백엔드 코드를 자동으로 실행할 수 있는 서버리스 프레임워크입니다. JavaScript, TypeScript 또는 Python 코드는 Google Cloud 인프라에 저장되고 관리형 환경에서 실행됩니다. 따라서 직접 서버를 관리하고 크기를 조절할 필요가 없습니다.
이미 Google Cloud에서 Cloud Functions를 사용하고 계신가요?
Firebase를 사용하면 얼마나 유용할지 자세히 알아보세요.
시작하기
사용 사례
주요 기능
Firebase 기능을 통합하고 Firebase를 Google Cloud에 연결합니다. |
작성한 함수는 Firebase 인증 트리거에서 Cloud Storage 트리거에 이르기까지 다양한 Firebase 및 Google Cloud 기능에서 생성된 이벤트에 응답할 수 있습니다.
Admin SDK와 Cloud Functions를 함께 사용하여 여러 Firebase 기능을 통합하고, 자체 웹훅을 작성하여 타사 서비스와 통합합니다.
Cloud Functions는 상용구 코드를 최소화하므로 함수 내에서 보다 간편하게 Firebase 및 Google Cloud를 사용할 수 있습니다. |
유지보수 불필요 |
명령줄의 명령어 하나만 입력하면 Google 서버에 JavaScript, TypeScript 또는 Python 코드가 배포됩니다.
코드가 배포되면 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로 함수 코드를 검색하고 함수 소스를 빌드합니다. Google Cloud 콘솔에서 Cloud Build 로그를 볼 수 있습니다.
- 빌드된 함수 코드의 컨테이너 이미지가 프로젝트의 비공개 Artifact Registry 저장소(
gcf-artifacts
라고 함)에 업로드되며 새 함수가 롤아웃됩니다.
- 이벤트 공급자가 함수의 조건과 일치하는 이벤트를 생성하면 코드가 호출됩니다. 함수에 Firebase Admin SDK를 사용하여 다른 Firebase 서비스에 액세스하는 데 사용할 수 있는 서비스 계정이 연결되어 있습니다.
- 함수가 다수의 이벤트를 처리 중인 경우 Google에서 작업을 신속하게 처리하기 위해 인스턴스를 더 만듭니다. 함수가 유휴 상태면 인스턴스가 정리됩니다.
- 업데이트된 코드를 배포하여 함수를 업데이트하면 이전 버전의 인스턴스가 Artifact Registry의 빌드 아티팩트와 함께 정리되고 새 인스턴스로 교체됩니다.
- 함수를 삭제하면 Artifact Registry의 관련 빌드 아티팩트와 함께 모든 인스턴스 및 zip 보관 파일이 정리됩니다.
함수와 이벤트 공급자 간의 연결이 삭제됩니다.
백그라운드 함수가 있는 이벤트를 리스닝하는 것 외에도 HTTP 요청 또는 클라이언트의 호출을 사용하여 직접 함수를 호출할 수 있습니다. Admin SDK를 통해 고정된 일정에 따라 함수를 트리거하거나 작업 함수를 큐에 추가할 수도 있습니다.
구현 경로
|
Cloud Functions 설정 |
Firebase CLI를 설치하고 Firebase 프로젝트에서 Cloud Functions를 초기화합니다. |
|
함수 작성 |
JavaScript 코드, TypeScript 코드 또는 Python 코드를 작성하여 Firebase 서비스, Google Cloud 서비스 또는 기타 이벤트 제공자의 이벤트를 처리합니다. |
|
함수 테스트 |
로컬 에뮬레이터를 사용하여 함수를 테스트합니다. |
|
배포 및 모니터링 |
사용한 만큼만 지불하는 Blaze 요금제로 프로젝트를 업그레이드하고 Firebase CLI를 사용하여 함수를 배포합니다. 그런 다음 Google Cloud 콘솔을 사용하여 로그를 확인하고 검색할 수 있습니다. |
다음 단계
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-08-17(UTC)
[null,null,["최종 업데이트: 2025-08-17(UTC)"],[],[],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)."]]