☁️ Cloud Functions – Cloud Storage Trigger
Google Cloud Functions integrates with Cloud Storage to automatically execute code when objects are created, updated, or deleted. This is powerful for automation, image/video processing, logging, and pipelines. 🚀
✅ Step-01: Introduction
We’ll create:
- A Cloud Storage Bucket
 - A Cloud Function with a Cloud Storage Event Trigger
 - Upload files and verify logs
 
✅ Step-02: Create Cloud Storage Bucket
- Navigate to Cloud Storage → CREATE
 - Enter: Bucket name: mycfdemobucket1021 (must be globally unique)
 - Leave all other options as default
 - Click CREATE
 
✅ Step-03: Create Cloud Function with Storage Trigger
Configuration Tab
- Function name: cf-demo3-events-storage
 - Region: us-central1
 - Trigger: Cloud Storage
 - Event Type: google.cloud.storage.object.v1.finalized (Object created/updated)
 - Bucket: mycfdemobucket1021
 - Leave all defaults → Click NEXT
 
Code Tab
- Runtime: Node.js 22
 - Use the auto-generated code (below)
 - Click Save and DEPLOY
 
const functions = require('@google-cloud/functions-framework');
// Register a CloudEvent callback with the Functions Framework that will
// be triggered by Cloud Storage.
functions.cloudEvent('helloGCS', cloudEvent => {
  console.log(`Event ID: ${cloudEvent.id}`);
  console.log(`Event Type: ${cloudEvent.type}`);
  const file = cloudEvent.data;
  console.log(`Bucket: ${file.bucket}`);
  console.log(`File: ${file.name}`);
  console.log(`Metageneration: ${file.metageneration}`);
  console.log(`Created: ${file.timeCreated}`);
  console.log(`Updated: ${file.updated}`);
});
✅ Step-04: Review Cloud Function Logs
- Go to: Cloud Functions → cf-demo3-events-storage → Logs
 - You’ll see logs once a file is uploaded or updated.
 
✅ Step-05: Upload a New File
- Navigate to Cloud Storage → Upload file → Select myfile1.txt
 
- Go to Cloud Function Logs → Verify file event logs
 
🎉 That’s it! You’ve successfully created a Cloud Function with a Cloud Storage Event Trigger. Every time a file is uploaded/updated, the function will log details such as bucket name, file name, and timestamps.
              





    
Top comments (0)