Skip to content

Commit f66a13b

Browse files
authored
minor fixes to tutorials (#21552)
1 parent 6f7193a commit f66a13b

File tree

2 files changed

+53
-48
lines changed
  • src/content/docs/pipelines/tutorials

2 files changed

+53
-48
lines changed

src/content/docs/pipelines/tutorials/query-data-with-motherduck/index.mdx

Lines changed: 48 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
updated: 2025-02-24
2+
updated: 2025-04-09
33
difficulty: Intermediate
44
content_type: 📝 Tutorial
55
pcx_content_type: tutorial
@@ -15,12 +15,10 @@ languages:
1515

1616
import { Render, PackageManagers, Details, WranglerConfig } from "~/components";
1717

18-
In this tutorial, you will learn how to ingest clickstream data from your website, using Pipelines. We'll also use Pipelines to load this data into an [R2 bucket](/r2/). You will also learn how to connect the bucket to MotherDuck. You will then query the data using MotherDuck.
18+
In this tutorial, you will learn how to ingest clickstream data to a [R2 bucket](/r2) using Pipelines. You will use the Pipeline binding to send the clickstream data to the R2 bucket from your Worker. You will also learn how to connect the bucket to MotherDuck. You will then query the data using MotherDuck.
1919

2020
For this tutorial, you will build a landing page of an e-commerce website. A user can click on the view button to view the product details or click on the add to cart button to add the product to their cart.
2121

22-
We will use a pipeline to ingest these click events, and load into an R2 bucket. We'll then use MotherDuck to query the events.
23-
2422
## Prerequisites
2523

2624
1. A [MotherDuck](https://motherduck.com/) account.
@@ -50,7 +48,7 @@ Create a new Worker project by running the following commands:
5048
product="workers"
5149
params={{
5250
category: "hello-world",
53-
type: "Worker only",
51+
type: "Worker + Assets",
5452
lang: "TypeScript",
5553
}}
5654
/>
@@ -61,20 +59,9 @@ Navigate to the `e-commerce-pipelines` directory:
6159
cd e-commerce-pipelines
6260
```
6361

64-
## 2. Create the frontend
65-
66-
Using Static Assets, you can serve the frontend of your application from your Worker. To use Static Assets, you need to add the required bindings to your `wrangler.toml` file.
62+
## 2. Update the frontend
6763

68-
<WranglerConfig>
69-
70-
```toml
71-
[assets]
72-
directory = "public"
73-
```
74-
75-
</WranglerConfig>
76-
77-
Next, create a `public` directory in the root of your project. Add an `index.html` file to the `public` directory. The `index.html` file should contain the following HTML code:
64+
Using Static Assets, you can serve the frontend of your application from your Worker. The above step creates a new Worker project with a default `public/index.html` file. Update the `public/index.html` file with the following HTML code:
7865

7966
<details>
8067
<summary>Select to view the HTML code</summary>
@@ -308,41 +295,72 @@ The `handleClick` function does the following:
308295
- Logs any errors that occur.
309296

310297
## 4. Create an R2 bucket
311-
We'll create a new R2 bucket to use as the sink for our pipeline. Create a new r2 bucket `clickstream-data` using the [Wrangler CLI](/workers/wrangler/):
298+
299+
You will create a new R2 bucket to use as the sink for our pipeline. Create a new r2 bucket `clickstream-data` using the [Wrangler CLI](/workers/wrangler/):
312300

313301
```sh
314302
npx wrangler r2 bucket create clickstream-data
315303
```
316304

317305
## 5. Create a pipeline
318-
You need to create a new pipeline and connect it to the R2 bucket we created in the previous step.
306+
You need to create a new pipeline and connect it to the R2 bucket you created in the previous step.
319307

320308
Create a new pipeline `clickstream-pipeline` using the [Wrangler CLI](/workers/wrangler/):
321309

322310
```sh
323-
npx wrangler pipelines create clickstream-pipeline --r2-bucket clickstream-data
311+
npx wrangler pipelines create clickstream-pipeline --r2-bucket clickstream-data --compression none --batch-max-seconds 5
324312
```
325313

326314
When you run the command, you will be prompted to authorize Cloudflare Workers Pipelines to create R2 API tokens on your behalf. These tokens are required by your Pipeline. Your Pipeline uses these tokens when loading data into your bucket. You can approve the request through the browser link which will open automatically.
327315

316+
:::note
317+
The above command creates a pipeline using two optional flags: `--compression none`, and `--batch-max-seconds 5`.
318+
319+
With these flags, your pipeline will deliver an uncompressed file of data to your R2 bucket every 5 seconds.
320+
321+
These flags are useful for testing, but we recommend keeping the default settings in a production environment.
322+
:::
323+
328324
```output
329-
🌀 Authorizing R2 bucket clickstream-data
330-
🌀 Creating pipeline named "clickstream-pipeline"
331-
✅ Successfully created pipeline "clickstream-pipeline" with id <PIPELINES_ID>
325+
✅ Successfully created Pipeline "clickstream-pipeline" with ID <PIPELINE_ID>
326+
327+
Id: <PIPELINE_ID>
328+
Name: clickstream-pipeline
329+
Sources:
330+
HTTP:
331+
Endpoint: https://<PIPELINE_ID>.pipelines.cloudflare.com
332+
Authentication: off
333+
Format: JSON
334+
Worker:
335+
Format: JSON
336+
Destination:
337+
Type: R2
338+
Bucket: clickstream-data
339+
Format: newline-delimited JSON
340+
Compression: NONE
341+
Batch hints:
342+
Max bytes: 100 MB
343+
Max duration: 300 seconds
344+
Max records: 10,000,000
345+
346+
🎉 You can now send data to your Pipeline!
347+
348+
Send data to your Pipeline's HTTP endpoint:
349+
350+
curl "https://<PIPELINE_ID>.pipelines.cloudflare.com" -d '[{"foo": "bar"}]'
332351
```
333352

334353
## 5. Send clickstream data to your pipeline
335-
We've setup the frontend of our application to make a call to the `/api/clickstream` route, everytime the user clicks on one of the
336354

337-
The front-end of the application makes a call to the `/api/clickstream` endpoint to send the clickstream data to your pipeline. The `/api/clickstream` endpoint is handled by a Worker in the `src/index.ts` file.
355+
You have setup the frontend of your application to make a call to the `/api/clickstream` route, everytime the user clicks on one of the buttons. The application makes a call to the `/api/clickstream` endpoint to send the clickstream data to your pipeline. The `/api/clickstream` endpoint is handled by a Worker in the `src/index.ts` file.
338356

339357
You will use the pipelines binding to send the clickstream data to your pipeline. In your `wrangler` file, add the following bindings:
340358

341359
<WranglerConfig>
342360

343361
```toml
344362
[[pipelines]]
345-
binding = "MY_PIPELINE"
363+
binding = "PIPELINE"
346364
pipeline = "clickstream-pipeline"
347365
```
348366

@@ -352,7 +370,7 @@ Next, update the type in the `worker-configuration.d.ts` file. Add the following
352370

353371
```ts title="worker-configuration.d.ts"
354372
interface Env {
355-
MY_PIPELINE: Pipeline;
373+
PIPELINE: Pipeline;
356374
}
357375
```
358376

@@ -366,7 +384,7 @@ export default {
366384
if (pathname === "/api/clickstream" && method === "POST") {
367385
const body = (await request.json()) as { data: any };
368386
try {
369-
await env.MY_PIPELINE.send([body.data]);
387+
await env.PIPELINE.send([body.data]);
370388
return new Response("OK", { status: 200 });
371389
} catch (error) {
372390
console.error(error);
@@ -472,4 +490,4 @@ This project serves as a foundation for building scalable, data-driven applicati
472490

473491
For your next steps, consider exploring more advanced querying techniques with MotherDuck, implementing real-time analytics, or integrating additional Cloudflare services to further optimize your application's performance and security.
474492

475-
You can find the source code of the application in the [GitHub repository](https://github.com/harshil1712/e-commerce-clickstream).
493+
You can find the source code of the application in the [GitHub repository](https://github.com/harshil1712/cf-pipelines-bindings-demo).

src/content/docs/pipelines/tutorials/send-data-from-client/index.mdx

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
updated: 2025-04-06
2+
updated: 2025-04-09
33
difficulty: Intermediate
44
content_type: 📝 Tutorial
55
pcx_content_type: tutorial
@@ -49,7 +49,7 @@ Create a new Worker project by running the following commands:
4949
product="workers"
5050
params={{
5151
category: "hello-world",
52-
type: "Worker only",
52+
type: "Worker + Assets",
5353
lang: "TypeScript",
5454
}}
5555
/>
@@ -60,20 +60,9 @@ Navigate to the `e-commerce-pipelines-client-side` directory:
6060
cd e-commerce-pipelines-client-side
6161
```
6262

63-
## 2. Create the website frontend
63+
## 2. Update the website frontend
6464

65-
Using [Workers Static Assets](/workers/static-assets/), you can serve the frontend of your application from your Worker. To use Static Assets, you need to add the required bindings to your `wrangler.toml` file.
66-
67-
<WranglerConfig>
68-
69-
```toml
70-
[assets]
71-
directory = "public"
72-
```
73-
74-
</WranglerConfig>
75-
76-
Next, create a `public` directory and add an `index.html` file. The `index.html` file should contain the following HTML code:
65+
Using Static Assets, you can serve the frontend of your application from your Worker. The above step creates a new Worker project with a default `public/index.html` file. Update the `public/index.html` file with the following HTML code:
7766

7867
<details>
7968
<summary>Select to view the HTML code</summary>
@@ -237,7 +226,7 @@ Sources:
237226
Format: JSON
238227
Destination:
239228
Type: R2
240-
Bucket: apr-6
229+
Bucket: clickstream-bucket
241230
Format: newline-delimited JSON
242231
Compression: NONE
243232
Batch hints:
@@ -439,8 +428,6 @@ You can connect the bucket to MotherDuck in several ways, which you can learn ab
439428

440429
Before connecting the bucket to MotherDuck, you need to obtain the Access Key ID and Secret Access Key for the R2 bucket. You can find the instructions to obtain the keys in the [R2 API documentation](/r2/api/tokens/).
441430

442-
Before connecting the bucket to MotherDuck, you need to obtain the Access Key ID and Secret Access Key for the R2 bucket. You can find the instructions to obtain the keys in the [R2 API documentation](/r2/api/tokens/).
443-
444431
1. Log in to the MotherDuck dashboard and select your profile.
445432
2. Navigate to the **Secrets** page.
446433
3. Select the **Add Secret** button and enter the following information:

0 commit comments

Comments
 (0)