Skip to content

πŸ“˜ InfluxDB Bucket Creation – Detailed Documentation

🧠 What is a Bucket?

In InfluxDB, a bucket is a logical container where time series data is stored. Think of it as a combination of a database and a retention policy:

  • It defines where data is stored
  • It determines how long the data is retained

Buckets are tied to an organization (org) and can be used to:

  • Collect sensor data
  • Store application metrics
  • Analyze log files
  • Visualize historical trends

πŸ› οΈ Prerequisites

Before creating a bucket, ensure you have the following:

Requirement Description
βœ… InfluxDB account Cloud or local OSS instance
βœ… Organization (org) ID Identifies your workspace in InfluxDB
βœ… Authentication token Admin or write access token
βœ… CLI or API tool access Optional, for non-UI methods

πŸ“‚ Bucket Attributes

Attribute Description
name Unique name of the bucket
org Organization under which the bucket is created
retentionRules Duration to keep data (default = infinite)
description (Optional) Notes about the bucket’s purpose

1️⃣ Method 1: Creating a Bucket via InfluxDB UI

πŸ”‘ Step-by-step Guide:

  1. Log In
    • Navigate to your InfluxDB dashboard (e.g., https://cloud2.influxdata.com).
    • Sign in with your credentials.
  2. Access the Buckets Page
    • On the left panel, go to β€œData” β†’ β€œBuckets”.
  3. Create a New Bucket
    • Click β€œ+ Create Bucket”.
    • Fill in the form:
      • Bucket Name: iot_sensor_data
      • Retention Period:
        • Default: Infinite
        • Custom: e.g., 30 days, 1 year, etc.
      • Optional: Add a description for better organization.
    • Click β€œCreate” to finish.

πŸ“ Note:

You can edit the bucket name later, but retention rules cannot be changed post-creation via the UI.


2️⃣ Method 2: Creating a Bucket via InfluxDB CLI

πŸ”§ Requirements:

Ensure the influx CLI is installed and configured:

influx config list

βœ… Example Command

influx bucket create \
  --name iot_sensor_data \
  --org my_org \
  --retention 30d \
  --description "Storing sensor data from IoT devices"

🧾 Flags Description:

Flag Description
--name Bucket name
--org Your organization name or ID
--retention Retention duration (e.g., 720h, 0s for infinite)
--description Optional description of the bucket

πŸ” Verify Creation

influx bucket list

3️⃣ Method 3: Creating a Bucket via InfluxDB API

πŸ“‘ Endpoint:

POST /api/v2/buckets

πŸ” Headers:

Authorization: Token YOUR_API_TOKEN
Content-Type: application/json

πŸ“„ Sample Request Body:

{
  "name": "iot_sensor_data",
  "orgID": "your_org_id_here",
  "description": "Stores IoT device data",
  "retentionRules": [
    {
      "type": "expire",
      "everySeconds": 2592000
    }
  ]
}
  • 2592000 seconds = 30 days

πŸ’¬ Sample cURL:

curl --request POST \
  https://us-west-2-1.aws.cloud2.influxdata.com/api/v2/buckets \
  --header "Authorization: Token YOUR_API_TOKEN" \
  --header "Content-Type: application/json" \
  --data '{
    "name": "iot_sensor_data",
    "orgID": "your_org_id_here",
    "description": "Stores IoT device data",
    "retentionRules": [
      {
        "type": "expire",
        "everySeconds": 2592000
      }
    ]
  }'

βœ… Best Practices

Tip Description
βœ… Use meaningful names e.g., prod_telemetry, dev_logs, metrics_internal
⏳ Apply appropriate retention Prevent bloated storage and unnecessary costs
πŸ“¦ Separate buckets for environments e.g., dev_, test_, prod_ buckets
πŸ”’ Apply access controls Use authorization tokens with specific permissions

πŸ”„ Post-Creation Operations

⏺️ Write Data to Bucket

Using the CLI:

influx write \
  --bucket iot_sensor_data \
  --org my_org \
  --precision s \
  --format lp \
  --file ./data.lp

Using Python client:

python
CopyEdit
from influxdb_client import InfluxDBClient, Point

client = InfluxDBClient(
    url="https://your-instance-url",
    token="YOUR_TOKEN",
    org="your_org"
)

write_api = client.write_api()
write_api.write(bucket="iot_sensor_data", record=Point("temperature").tag("device", "sensor1").field("value", 25.3))

πŸ“Š Query Data

Flux query via CLI:

influx query 'from(bucket:"iot_sensor_data") |> range(start: -1h)'

🧹 Clean-Up (Optional)

Delete a Bucket

CLI:

influx bucket delete --name iot_sensor_data --org my_org

API:

DELETE /api/v2/buckets/{bucketID}