Skip to main content

Get Bucket

Retrieves detailed metadata and configuration attributes of a Google Cloud Storage bucket.

Common Properties​

  • Name - The custom name of the node.
  • Color - The custom color of the node.
  • Delay Before (sec) - Waits in seconds before executing the node.
  • Delay After (sec) - Waits in seconds after executing node.
  • Continue On Error - Automation will continue regardless of any error. The default value is false.
info

If the ContinueOnError property is true, no error is caught when the project is executed, even if a Catch node is used.

Inputs​

  • GCS Client Id - The client identifier obtained from the Connect node. Optional if credentials are provided directly.
  • Bucket Name - The name of the bucket to retrieve information about.

Output​

  • Bucket - Object containing bucket metadata and attributes:
    • Created - Creation timestamp of the bucket
    • Name - The bucket name
    • StorageClass - Storage class (Standard, Nearline, Coldline, Archive)
    • UniformBucketLevelAccess - Access control configuration
    • Labels - Key-value labels assigned to the bucket

Stored in message context as bucket.

Options​

  • Credentials - Google Cloud service account credentials (optional). Use this instead of GCS Client Id for direct authentication without Connect node.

How It Works​

The Get Bucket node retrieves bucket information. When executed, the node:

  1. Establishes connection using either GCS Client Id or credentials
  2. Validates bucket name
  3. Retrieves bucket attributes from GCS
  4. Formats information into structured object
  5. Returns bucket details

Example​

Get Bucket Details​

// Input:
// Bucket Name: "my-production-data"

// Output in message.bucket:
// {
// Created: "2024-01-15T10:30:00Z",
// Name: "my-production-data",
// StorageClass: "STANDARD",
// UniformBucketLevelAccess: { Enabled: true },
// Labels: { environment: "production", team: "data" }
// }

Check Storage Class​

// After Get Bucket:
const bucket = message.bucket;

console.log(`Bucket: ${bucket.Name}`);
console.log(`Storage Class: ${bucket.StorageClass}`);

if (bucket.StorageClass === 'STANDARD') {
console.log('Using standard storage');
// Consider moving to Nearline for cost savings
}

Verify Bucket Configuration​

// Check bucket settings
const bucket = message.bucket;

console.log('Bucket Configuration:');
console.log(`Name: ${bucket.Name}`);
console.log(`Created: ${bucket.Created}`);
console.log(`Uniform Access: ${bucket.UniformBucketLevelAccess.Enabled}`);

// Verify labels
if (bucket.Labels) {
console.log('Labels:', bucket.Labels);
}

Audit Bucket Settings​

// Audit multiple buckets
// Use with Loop node after List Buckets

const bucket = message.bucket;

const auditReport = {
name: bucket.Name,
storageClass: bucket.StorageClass,
uniformAccess: bucket.UniformBucketLevelAccess.Enabled,
hasLabels: bucket.Labels && Object.keys(bucket.Labels).length > 0,
age: calculateAge(bucket.Created)
};

console.log('Audit Report:', auditReport);

Requirements​

  • Either valid GCS Client Id OR credentials provided directly
  • Valid bucket name that exists
  • Appropriate IAM permissions:
    • storage.buckets.get permission
    • roles/storage.objectViewer or higher

Error Handling​

Error CodeDescription
ErrInvalidArgBucket Name is empty or invalid

Common error scenarios:

  • Bucket doesn't exist
  • Insufficient permissions
  • Invalid bucket name
  • Network connectivity issues

Usage Notes​

  • Returns current bucket configuration
  • Useful for validation and auditing
  • Labels are included in output
  • Access control settings provided
  • Creation timestamp available
  • Read-only operation, doesn't modify bucket
  • Information is current at time of execution

Tips for Effective Use​

  • Use for bucket configuration validation
  • Check storage class before operations
  • Verify access control settings
  • Audit bucket labels and metadata
  • Combine with List Buckets for full inventory
  • Use in conditional logic based on bucket properties
  • Log bucket details for compliance

Common Errors and Solutions​

Error: "Bucket Name cannot be empty"

  • Solution: Provide valid bucket name

Bucket not found

  • Solution: Verify bucket name is correct
  • Check if bucket exists in project
  • Ensure correct project is being used

Permission denied

  • Solution: Grant storage.buckets.get permission
  • Verify service account has viewer role or higher

Unexpected bucket properties

  • Solution: Verify you're accessing correct bucket
  • Check if bucket configuration was recently changed

Use Cases​

Configuration Validation

  • Verify bucket settings before operations
  • Check storage class for cost optimization
  • Validate access control configuration

Compliance Auditing

  • Audit bucket configurations
  • Verify uniform access is enabled
  • Check required labels are present

Conditional Processing

  • Route logic based on storage class
  • Handle buckets differently based on labels
  • Adjust operations based on access control

Documentation and Reporting

  • Generate bucket inventory reports
  • Document bucket configurations
  • Track bucket metadata over time

Cost Analysis

  • Identify storage class for cost calculations
  • Find buckets suitable for class changes
  • Analyze label-based cost allocation

Advanced Examples​

Validate Required Labels​

const bucket = message.bucket;

const requiredLabels = ['environment', 'team', 'cost-center'];
const missingLabels = requiredLabels.filter(
label => !bucket.Labels || !bucket.Labels[label]
);

if (missingLabels.length > 0) {
console.error('Missing required labels:', missingLabels);
// Update bucket with missing labels
} else {
console.log('All required labels present');
}

Storage Class Optimization​

const bucket = message.bucket;

// Check if bucket is candidate for class change
const createdDate = new Date(bucket.Created);
const ageInDays = (new Date() - createdDate) / (1000 * 60 * 60 * 24);

if (bucket.StorageClass === 'STANDARD' && ageInDays > 90) {
console.log(`Bucket ${bucket.Name} is ${ageInDays} days old`);
console.log('Consider moving to Nearline or Coldline');
// Trigger Update Bucket node to change class
}

Access Control Audit​

const bucket = message.bucket;

console.log(`Bucket: ${bucket.Name}`);
console.log(`Uniform Access: ${bucket.UniformBucketLevelAccess.Enabled}`);

if (!bucket.UniformBucketLevelAccess.Enabled) {
console.warn('Bucket uses fine-grained ACLs');
console.log('Consider enabling uniform access for better security');
}

Generate Bucket Report​

const bucket = message.bucket;

const report = {
'Bucket Name': bucket.Name,
'Storage Class': bucket.StorageClass,
'Created': new Date(bucket.Created).toLocaleDateString(),
'Uniform Access': bucket.UniformBucketLevelAccess.Enabled ? 'Yes' : 'No',
'Labels': bucket.Labels ? Object.keys(bucket.Labels).length : 0,
'Environment': bucket.Labels?.environment || 'Not Set',
'Team': bucket.Labels?.team || 'Not Set'
};

console.table(report);