| [ Web Proxy ] |
| Viewing: https://developers.cloudflare.com/pipelines/getting-started/ | [Back] [Original] |
This guide will instruct you through:
Node.js .Node.js version manager
Use a Node version manager like Volta or nvm to avoid permission issues and change Node.js versions. Wrangler, discussed later in this guide, requires a Node version of 16.17.0 or later.
Pipelines must authenticate to R2 Data Catalog with an R2 API token that has catalog and R2 permissions.
In the Cloudflare dashboard, go to the R2 object storage page.
Go to Overview ↗Select Manage API tokens.
Select Create Account API token.
Give your API token a name.
Under Permissions, select the Admin Read & Write permission.
Select Create Account API Token.
Note the Token value.
Note
This token also includes the R2 SQL Read permission, which allows you to query your data with R2 SQL.
First, create a schema file that defines your ecommerce data structure:
Create schema.json:
{
"fields": [
{
"name": "user_id",
"type": "string",
"required": true
},
{
"name": "event_type",
"type": "string",
"required": true
},
{
"name": "product_id",
"type": "string",
"required": false
},
{
"name": "amount",
"type": "float64",
"required": false
}
]
}Use the interactive setup to create a pipeline that writes to R2 Data Catalog:
npx wrangler pipelines setupNote
The setup command automatically creates the R2 bucket and enables R2 Data Catalog if they do not already exist, so you do not need to create them beforehand.
Follow the prompts:
Pipeline name: Enter ecommerce
Stream configuration:
yesno (for simplicity)noLoad from fileschema.json (or your file path)Sink configuration:
Data Catalog (Iceberg)Simple (recommended defaults)pipelines-tutorial (created automatically if it does not exist)ecommerceReview: Confirm the summary and select Create resources
SQL transformation: Choose Simple ingestion (SELECT * FROM stream)
Note
If you make a mistake during setup (such as an invalid name or incorrect credentials), you will be prompted to retry rather than needing to restart the entire setup process.
Advanced mode options
If you select Advanced instead of Simple during sink configuration, you can customize the following additional options:
default)After setup completes, the command outputs a configuration snippet for your Wrangler file, a Worker binding example with sample data, and a curl command for the HTTP endpoint. Note the HTTP endpoint URL and the pipelines configuration for use in the following steps.
You can also pre-set the pipeline name using the --name flag:
npx wrangler pipelines setup --name ecommerceIn the Cloudflare dashboard, go to R2 object storage.
Go to Overview ↗Select Create bucket and enter the bucket name: pipelines-tutorial.
Select Create bucket.
Select the bucket, switch to the Settings tab, scroll down to R2 Data Catalog, and select Enable.
Once enabled, note the Catalog URI and Warehouse name.
Go to Pipelines > Pipelines.
Go to Pipelines ↗Select Create Pipeline.
Connect to a Stream:
ecommerceDefine Input Schema:
{
"fields": [
{
"name": "user_id",
"type": "string",
"required": true
},
{
"name": "event_type",
"type": "string",
"required": true
},
{
"name": "product_id",
"type": "string",
"required": false
},
{
"name": "amount",
"type": "float64",
"required": false
}
]
}
Define Sink:
pipelines-tutorialdefaultecommerce10 secondsCredentials:
Pipeline Definition:
INSERT INTO ecommerce_sink SELECT * FROM ecommerce_stream;
After pipeline creation, note the Stream ID for the next step.
Send ecommerce events to your pipeline's HTTP endpoint:
curl -X POST https://{stream-id}.ingest.cloudflare.com \
-H "Content-Type: application/json" \
-d '[
{
"user_id": "user_12345",
"event_type": "purchase",
"product_id": "widget-001",
"amount": 29.99
},
{
"user_id": "user_67890",
"event_type": "view_product",
"product_id": "widget-002"
},
{
"user_id": "user_12345",
"event_type": "add_to_cart",
"product_id": "widget-003",
"amount": 15.50
}
]'
Replace {stream-id} with your actual stream endpoint from the pipeline setup.
In the Cloudflare dashboard, go to the R2 object storage page.
Select your bucket: pipelines-tutorial.
You should see Iceberg metadata files and data files created by your pipeline. If you are not seeing any files in your bucket, wait a couple of minutes and try again.
The data is organized in the Apache Iceberg format with metadata tracking table versions.
Set up your environment to use R2 SQL:
export WRANGLER_R2_SQL_AUTH_TOKEN=YOUR_API_TOKEN
Or create a .env file with:
WRANGLER_R2_SQL_AUTH_TOKEN=YOUR_API_TOKEN
Where YOUR_API_TOKEN is the token you created in step 1. For more information on setting environment variables, refer to Wrangler system environment variables.
Query your data:
npx wrangler r2 sql query "YOUR_WAREHOUSE_NAME" "
SELECT
user_id,
event_type,
product_id,
amount
FROM default.ecommerce
WHERE event_type = 'purchase'
LIMIT 10"
Replace YOUR_WAREHOUSE_NAME with the warehouse name noted during pipeline setup. You can find it in the Cloudflare dashboard under R2 object storage > your bucket > Settings > R2 Data Catalog.
You can also query this table with any engine that supports Apache Iceberg. To learn more about connecting other engines to R2 Data Catalog, refer to Connect to Iceberg engines.
| Web Proxy Viewer | New URL | Original Page |