Tutorial Tutorial Tutorial Developer Platform Developer Platform Developer Platform ~40 phút ~40 min ~40 នាទី Đồng bộ 2026-06-10 Synced 2026-06-10 ធ្វើសមកាល 2026-06-10

Triển khai một công nhân Deploy a Worker ការបាត់បង់បុគ្គល

Hướng dẫn chi tiết đồng bộ từ docs Cloudflare — mỗi section có backlink tới đúng vị trí trên trang gốc. Detailed guide synced from Cloudflare docs — each section links to the matching anchor on the official page. មគ្គុទ្ទេសក៍លម្អិតធ្វើសមកាលពី docs Cloudflare — ផ្នែកនីមួយៗមានតំណទៅទីតាំងត្រូវគ្នានៅទំព័រផ្លូវការ។

← Danh mục ← Catalog ← បញ្ជី

Giải thích nhanh Quick context បរិបទរហ័ស

Thuộc Developer Platform — thực hành triển khai code, API và dữ liệu trên edge/serverless. Tutorial «Triển khai Worker» giúp bạn làm quen luồng triển khai thật — phù hợp đọc trước khi mở tài liệu gốc tiếng Anh. Docs gốc chia khoảng 5 bước chính; bản tóm tắt dưới đây giúp bạn nắm khung trước khi làm theo từng lệnh.

In this tutorial, you will follow step-by-step instructions to deploy a Hello World application using Cloudflare Workers and Pulumi infrastructure as code (IaC).

ក្នុងកម្មវិធីបច្ចេកទេសនេះអ្នកនឹងធ្វើដូចម្តេចដើម្បីដំឡើងកម្មវិធី Hello World ដែលប្រើ Cloudflare Workers និងប្រព័ន្ធប្រតិបត្តិការ Pulumi ដូចជាកូដ (IaC) ។

Lưu ý Note ចំណាំ

Lưu ý trước khi làm Notes before you start ចំណាំមុនពេលចាប់ផ្តើម

  • Đây là bản tóm tắt trên Orange Cloud Learning Hub — không thay thế tài liệu chính thức.
  • Luôn mở liên kết «Tài liệu gốc» bên dưới khi cần lệnh CLI, snippet code và ảnh minh họa đầy đủ.
  • Kiểm tra token/API và state backend trước khi chạy trên môi trường production.
  • Docs Cloudflare cập nhật thường xuyên — đối chiếu ngày «Rà soát lần cuối» trên trang gốc khi triển khai production.
  • This is a summary on Orange Cloud Learning Hub — it does not replace the official documentation.
  • Open the Official docs link below for CLI commands, code snippets, and full screenshots.
  • Verify API tokens and the state backend before running against production.
  • Cloudflare docs change frequently — verify the Last reviewed date on the official page before production use.
  • នេះគឺជាការបញ្ជាក់អំពី Orange Cloud Learning Hub — វាគឺជាការផ្លាស់ប្តូរនៃឯកសារផ្លូវការ។
  • ចុចតំណភ្ជាប់ Docs Official នៅខាងក្រោមសម្រាប់ការបញ្ជា CLI, សៀវភៅកូដនិងរូបថតពេញលេញ។
  • សូមពិនិត្យមើល API tokens និងការបង្វិលប្រព័ន្ធប្រតិបត្តិការមុនពេលធ្វើការប្រឆាំងនឹងការផលិត។
  • Cloudflare បានផ្លាស់ប្តូរជាធម្មតានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅ។

Tài liệu gốc — rà soát lần cuối: over 1 year ago Official docs — last reviewed: over 1 year ago ឯកសារផ្លូវការ — ពិនិត្យចុងក្រោយ: over 1 year ago

Overview Overview Overview

In this tutorial, you will follow step-by-step instructions to deploy a Hello World application bằng Cloudflare Workers and Pulumi infrastructure as code (IaC) to familiarize yourself with the resource management lifecycle. In particular, you will create a Worker, a Route, and a…

Read the "Overview" section below — open the official docs link for full screenshots and configuration tabs.

អានផ្នែក «Overview» ខាងក្រោម — បើកតំណ docs ផ្លូវការសម្រាប់រូបភាព និង tab កំណត់។

Mở section docs gốc ↗ Open source section ↗ បើកផ្នែក docs ផ្លូវការ ↗
Trong hướng dẫn này, bạn sẽ làm theo các hướng dẫn từng bước để triển khai ứng dụng Hello World sử dụng Cloudflare Workers và cơ sở hạ tầng Pulumi như mã (IaC) để làm quen với vòng đời quản lý tài nguyên. Đặc biệt, bạn sẽ tạo một Worker, một Route, và một DNS Record để access ứng dụng trước khi dọn dẹp tất cả các tài nguyên.
In this tutorial, you will follow step-by-step instructions to deploy a Hello World application using Cloudflare Workers and Pulumi infrastructure as code (IaC) to familiarize yourself with the resource management lifecycle. In particular, you will create a Worker, a Route, and a DNS Record to access the application before cleaning up all the resources.
ក្នុងកម្មវិធីបច្ចេកទេសនេះអ្នកនឹងធ្វើដូចម្តេចដើម្បីដំឡើងកម្មវិធី Hello World ដោយប្រើកម្មវិធី Cloudflare Workers និង Pulumi Infrastructure as Code (IaC) ដើម្បីធ្វើឱ្យអ្នកដឹងអំពីជីវិតនៃការគ្រប់គ្រងឧបករណ៍។ ជាពិសេសអ្នកនឹងបង្កើតការងារ, ផ្លូវ, និង DNS ពិនិត្យឡើងវិញទៅ access កម្មវិធីមុនពេលការចែកចាយទាំងអស់នៃវិស័យ។
Bạn sẽ cung cấp các tài nguyên đủ điều kiện theo các ưu đãi cấp miễn phí cho cả Pulumi Cloud và Cloudflare.
You will provision resources that qualify under free tier offerings for both Pulumi Cloud and Cloudflare.
អ្នកនឹងផ្តល់សេវាកម្មដែលមានសមត្ថភាពក្នុងការផ្តល់សេវាកម្មដោយឥតគិតថ្លៃសម្រាប់ Pulumi Cloud និង Cloudflare ។

Trước khi bạn bắt đầu Before you begin មុនពេលដែលអ្នកចាប់ផ្តើម

Phần «Before you begin» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.

Read the "Before you begin" section below — open the official docs link for full screenshots and configuration tabs.

អានផ្នែក «មុនពេលដែលអ្នកចាប់ផ្តើម» ខាងក្រោម — បើកតំណ docs ផ្លូវការសម្រាប់រូបភាព និង tab កំណត់។

Mở section docs gốc ↗ Open source section ↗ បើកផ្នែក docs ផ្លូវការ ↗
Đảm bảo bạn có:
Ensure you have:
សូមធានាថាអ្នកមាន:
  • Một tài khoản Cloudflare và API Token với quyền chỉnh sửa các tài nguyên trong hướng dẫn này. Nếu bạn cần, hãy đăng ký Cloudflare account ↗ trước khi tiếp tục. Token của bạn phải có những điều sau đây:
  • A Cloudflare account and API Token with permission to edit the resources in this tutorial. If you need to, sign up for a Cloudflare account ↗ before continuing. Your token must have the following:
  • ទិន្នន័យ Cloudflare និង API ស្លាកជាមួយនឹងការអនុញ្ញាតឱ្យធ្វើតេស្តឧបករណ៍នៅក្នុងបច្ចុប្បន្ននេះ ប្រសិនបើអ្នកត្រូវការ, សូមចុះឈ្មោះសម្រាប់ Cloudflare account ↗ មុនពេលដំណើរការ។ គំនិតរបស់អ្នកគួរតែមានដូចខាងក្រោម:
Account-Workers Scripts-Edit quyền Zone-Workers Route-Edit quyền * Zone-DNS-Edit quyền
Account-Workers Scripts-Edit permission Zone-Workers Route-Edit permission * Zone-DNS-Edit permission
Account-Workers Scripts-Edit អនុញ្ញាត Zone-Workers Route-Edit អនុញ្ញាត * Zone-DNS-Edit អនុញ្ញាត
  • កុំព្យូទ័រ Pulumi Cloud អ្នកអាចចុះឈ្មោះសម្រាប់ always-free individual tier ↗ ។
  • Pulumi CLI ត្រូវបានដំឡើងនៅលើម៉ាស៊ីនរបស់អ្នក។
  • ការ Pulumi-supported programming language ↗ បានកំណត់។ (TypeScript, JavaScript, Python, Go, .NET, Java ឬប្រើ YAML)
  • មួយ Cloudflare-ឧបករណ៍គ្រប់គ្រង។ សូមបញ្ចប់ Add a site tutorial ដើម្បីបង្កើតអាសយដ្ឋានរបស់អ្នកនៅក្រោម Cloudflare ។

Liên kết liên quan (docs Cloudflare) Related links (Cloudflare docs) តំណពាក់ព័ន្ធ (docs Cloudflare)

1.Điều Khởi đầu dự án của bạn 1. Initialize your project 1 ។ ចាប់ផ្តើមគម្រោងរបស់អ្នក

Phần «Khởi tạo your dự án» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.

Read the "1. Initialize your project" section below — open the official docs link for full screenshots and configuration tabs.

អានផ្នែក «1 ។ ចាប់ផ្តើមគម្រោងរបស់អ្នក» ខាងក្រោម — បើកតំណ docs ផ្លូវការសម្រាប់រូបភាព និង tab កំណត់។

Mở section docs gốc ↗ Open source section ↗ បើកផ្នែក docs ផ្លូវការ ↗
Một dự án Pulumi là một bộ sưu tập các tệp trong một thư mục chuyên dụng mô tả cơ sở hạ tầng bạn muốn tạo. Thư mục dự án Pulumi được xác định bằng tệp Pulumi.yaml cần thiết. Bạn sẽ sử dụng Pulumi CLI để tạo và cấu hình một dự án mới.
A Pulumi project is a collection of files in a dedicated folder that describes the infrastructure you want to create. The Pulumi project folder is identified by the required Pulumi.yaml file. You will use the Pulumi CLI to create and configure a new project.
គម្រោង Pulumi គឺជាក្រុមប្រឹក្សាភិបាលនៃឯកសារនៅក្នុងកំណត់ឯកសារដែលបានបង្ហាញនូវវិជ្ជាជីវៈដែលអ្នកចង់បង្កើត។ មូលដ្ឋានគម្រោង Pulumi ត្រូវបានគេស្គាល់ដោយឯកសារ Pulumi.yaml ដែលត្រូវការ។ អ្នកនឹងប្រើ Pulumi CLI ដើម្បីបង្កើតនិងកំណត់គម្រោងថ្មី។

A ơi Tạo Directory a. Create a directory A ។ បានបង្កើត Directory

Phần «. Create directory» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.

Read the "a. Create a directory" section below — open the official docs link for full screenshots and configuration tabs.

អានផ្នែក «A ។ បានបង្កើត Directory» ខាងក្រោម — បើកតំណ docs ផ្លូវការសម្រាប់រូបភាព និង tab កំណត់។

Mở section docs gốc ↗ Open source section ↗ បើកផ្នែក docs ផ្លូវការ ↗
Sử dụng một thư mục mới và trống cho hướng dẫn này.
Use a new and empty directory for this tutorial.
ប្រព័ន្ធ ប្រតិបត្តិការ iOS និង iOS ប្រព័ន្ធ ប្រតិបត្តិការ iOS ប្រព័ន្ធ ប្រតិបត្តិការ iOS ប្រតិបត្តិការ iOS ប្រតិបត្តិការ iOS ប្រតិបត្តិការ iOS ប្រតិបត្តិការ iOS ប្រតិបត្តិការ iOS ប្រតិបត្តិការ iOS ប្រតិបត្តិការ iOS
Cửa sổ Terminal
Terminal window
បង្វិល Terminal
text
mkdir serverless-cloudflare

cd serverless-cloudflare

B . Tải về Pulumi Cloud b. Login to Pulumi Cloud B ។ លក្ខណៈពិសេសសម្រាប់ Pulumi Cloud

Phần «b. Login to Pulumi Cloud» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.

Read the "b. Login to Pulumi Cloud" section below — open the official docs link for full screenshots and configuration tabs.

អានផ្នែក «B ។ លក្ខណៈពិសេសសម្រាប់ Pulumi Cloud» ខាងក្រោម — បើកតំណ docs ផ្លូវការសម្រាប់រូបភាព និង tab កំណត់។

Mở section docs gốc ↗ Open source section ↗ បើកផ្នែក docs ផ្លូវការ ↗
Pulumi Cloud ↗ là một dịch vụ được lưu trữ cung cấp một nền tảng an toàn và có thể mở rộng để quản lý cơ sở hạ tầng của bạn dưới dạng mã. Bạn sẽ sử dụng nó để lưu trữ cấu hình backend Pulumi của bạn.
Pulumi Cloud ↗ is a hosted service that provides a secure and scalable platform for managing your infrastructure as code. You will use it to store your Pulumi backend configurations.
Pulumi Cloud ↗ គឺជាសេវាកម្មដែលមានអត្ថប្រយោជន៍ដែលផ្តល់នូវបណ្តាញសុវត្ថិភាពនិងអាចកាត់បន្ថយសម្រាប់ការគ្រប់គ្រងវិជ្ជាជីវៈរបស់អ្នកជាកូដ។ អ្នកនឹងប្រើវាដើម្បីរក្សាទុកការផ្លាស់ប្តូរ Pulumi របស់អ្នក។
Nhấn Enter để đăng nhập vào tài khoản Pulumi Cloud của bạn thông qua trình duyệt. Ngoài ra, bạn có thể cung cấp một Pulumi Cloud access token ↗.
At the prompt, press Enter to log into your Pulumi Cloud account via the browser. Alternatively, you may provide a Pulumi Cloud access token ↗.
សូមចុច Enter ដើម្បីចូលទៅក្នុងគណនី Pulumi Cloud របស់អ្នកតាមរយៈបណ្តាញ។ ទោះជាយ៉ាងណាអ្នកអាចផ្តល់ Pulumi Cloud access token ↗ ។
Cửa sổ Terminal
Terminal window
បង្វិល Terminal
text
pulumi login

C . Tạo một chương trình mới c. Create a new program C ។ បង្កើតកម្មវិធីថ្មី

Phần «C. Create mới program» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.

Read the "c. Create a new program" section below — open the official docs link for full screenshots and configuration tabs.

អានផ្នែក «C ។ បង្កើតកម្មវិធីថ្មី» ខាងក្រោម — បើកតំណ docs ផ្លូវការសម្រាប់រូបភាព និង tab កំណត់។

Mở section docs gốc ↗ Open source section ↗ បើកផ្នែក docs ផ្លូវការ ↗
Một chương trình Pulumi là mã viết bằng chữ supported programming language ↗ xác định tài nguyên cơ sở hạ tầng.
A Pulumi program is code written in a supported programming language ↗ that defines infrastructure resources.
កម្មវិធី Pulumi គឺជាកូដដែលបានសរសេរនៅក្នុង supported programming language ↗ ដែលតម្រូវឱ្យកំណត់ឧបករណ៍វិជ្ជាជីវៈ។
Để tạo một chương trình, hãy chọn ngôn ngữ của bạn và chạy lệnh pulumi:
To create a program, select your language of choice and run the pulumi command:
ដើម្បីបង្កើតកម្មវិធីអ្នកចង់ជ្រើសរើសភាសារបស់អ្នកនិងដំណើរការការ pulumi:
Cửa sổ Terminal
Terminal window
បង្វិល Terminal
text
pulumi new javascript --name serverless-cloudflare --yes

# wait a few seconds while the project is initialized
Cửa sổ Terminal
Terminal window
បង្វិល Terminal
text
pulumi new typescript --name serverless-cloudflare --yes

# wait a few seconds while the project is initialized
Cửa sổ Terminal
Terminal window
បង្វិល Terminal
text
pulumi new python --name serverless-cloudflare --yes

# wait a few seconds while the project is initialized
Cửa sổ Terminal
Terminal window
បង្វិល Terminal
text
pulumi new go --name serverless-cloudflare --yes

# wait a few seconds while the project is initialized
Cửa sổ Terminal
Terminal window
បង្វិល Terminal
text
pulumi new java --name serverless-cloudflare --yes

# wait a few seconds while the project is initialized
Cửa sổ Terminal
Terminal window
បង្វិល Terminal
text
pulumi new csharp --name serverless-cloudflare --yes

# wait a few seconds while the project is initialized
Cửa sổ Terminal
Terminal window
បង្វិល Terminal
text
pulumi new yaml --name serverless-cloudflare --yes

D . Tạo Stack d. Create a stack លោក D ។ បានបង្កើត Stack

Phần «D. Create stack» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.

Read the "d. Create a stack" section below — open the official docs link for full screenshots and configuration tabs.

អានផ្នែក «លោក D ។ បានបង្កើត Stack» ខាងក្រោម — បើកតំណ docs ផ្លូវការសម្រាប់រូបភាព និង tab កំណត់។

Mở section docs gốc ↗ Open source section ↗ បើកផ្នែក docs ផ្លូវការ ↗
Một Pulumi stack ↗ là một trường hợp của một chương trình Pulumi. Stacks có thể được cấu hình độc lập và có thể đại diện cho các môi trường khác nhau (phát triển, triển lãm, sản xuất) hoặc các chi nhánh tính năng. Đối với hướng dẫn này, bạn sẽ sử dụng dev stack.
A Pulumi stack ↗ is an instance of a Pulumi program. Stacks are independently configurable and may represent different environments (development, staging, production) or feature branches. For this tutorial, you'll use the dev stack.
ប្រតិបត្តិការ Pulumi stack ↗ គឺជាប្រតិបត្តិការ Pulumi ។ កញ្ចប់អាចត្រូវបានកំណត់ដោយខ្លួនឯងហើយអាចបង្ហាញនូវបរិស្ថានផ្សេងគ្នា (ការអភិវឌ្ឍ, ការដំឡើង, ការផលិត) ឬកញ្ចប់លក្ខណៈពិសេស។ សម្រាប់វគ្គបណ្តុះបណ្តាលនេះអ្នកនឹងប្រើថ្នាំ dev ។
Để khởi động dev stack của bạn, chạy:
To instantiate your dev stack, run:
ប្រសិនបើអ្នកចង់បង្កើត dev stack របស់អ្នក, ធ្វើការដូចខាងក្រោម:
Cửa sổ Terminal
Terminal window
បង្វិល Terminal
text
pulumi up --yes

# wait a few seconds for the stack to be instantiated.
Bạn chưa xác định bất kỳ tài nguyên nào tại thời điểm này, vì vậy bạn sẽ có một stack trống.
You have not defined any resources at this point, so you'll have an empty stack.
ប្រសិនបើអ្នកមិនបានកំណត់សម្ភារៈណាមួយនៅពេលនេះ, ដូច្នេះអ្នកនឹងមានសម្ភារៈបិទ។

E ơi Save your ứng dụng settings e. Save your application settings អាសយដ្ឋាន រក្សាទុកកំណត់កម្មវិធីរបស់អ្នក

Phần «E. Save your ứng dụng settings» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.

Read the "e. Save your application settings" section below — open the official docs link for full screenshots and configuration tabs.

អានផ្នែក «អាសយដ្ឋាន រក្សាទុកកំណត់កម្មវិធីរបស់អ្នក» ខាងក្រោម — បើកតំណ docs ផ្លូវការសម្រាប់រូបភាព និង tab កំណត់។

Mở section docs gốc ↗ Open source section ↗ បើកផ្នែក docs ផ្លូវការ ↗
Trong bước này, bạn sẽ lưu cài đặt ứng dụng của mình trong Pulumi ESC Environment ↗, một tập tin YAML chứa cấu hình và bí mật. Chúng có thể được truy cập theo nhiều cách, bao gồm một chương trình Pulumi. Tất cả các môi trường ESC đều an toàn trong tài khoản Pulumi Cloud của bạn và có thể được quản lý hoàn toàn thông qua Pulumi CLI. Đối với hướng dẫn này, bạn sẽ lưu trữ các giá trị sau:
In this step, you will store your application settings in a Pulumi ESC Environment ↗, a YAML file containing configurations and secrets. These can be accessed in several ways, including a Pulumi program. All ESC Environments securely reside in your Pulumi Cloud account and can be fully managed via the Pulumi CLI. For this tutorial, you will store the following values:
ក្នុងដំណោះស្រាយនេះអ្នកនឹងរក្សាទុកកំណត់កម្មវិធីរបស់អ្នកនៅក្នុង Pulumi ESC Environment ↗ ដែលជាឯកសារ YAML ដែលមានកំណត់ដំណោះស្រាយនិងសៀវភៅ។ នេះអាចត្រូវបានចូលទៅក្នុងវិធីផ្សេងទៀត, រួមទាំងកម្មវិធី Pulumi ។ ប្រព័ន្ធប្រតិបត្តិការ ESC ទាំងអស់មានទីតាំងស្ថិតនៅក្នុងគណនី Pulumi Cloud របស់អ្នកហើយអាចត្រូវបានគ្រប់គ្រងពេញលេញតាមរយៈ Pulumi CLI ។ សម្រាប់វគ្គបណ្តុះបណ្តាលនេះអ្នកនឹងរក្សាទុកតម្លៃដូចខាងក្រោម:
  • Của bạn Cloudflare account ID
  • Một hợp lệ Cloudflare API token.
  • một domain. Ví dụ như example.com.
  • Your Cloudflare account ID.
  • A valid Cloudflare API token.
  • A domain. For instance, example.com.
  • ទូរស័ព្ទរបស់អ្នក Cloudflare account ID ។
  • កម្រិតខ្ពស់ Cloudflare API token
  • នេះជា Domain ។ ដូចជា example.com ។
Cửa sổ Terminal
Terminal window
បង្វិល Terminal
text
# Give your new ESC Environment a name

E=hello-world/dev-env


# Initialize the new ESC Environment

pulumi config env init --env $E --yes
text
Creating environment hello-world/dev-env for stack dev...
Cửa sổ Terminal
Terminal window
បង្វិល Terminal
text
# Replace abc123 with your Cloudflare account ID

pulumi env set $E --plaintext pulumiConfig.accountId abc123


# Replace API_TOKEN with your Cloudflare API token

pulumi env set $E --secret pulumiConfig.cloudflare:apiToken API_TOKEN


# Replace example.com with your domain

pulumi env set $E --plaintext pulumiConfig.domain example.com

Liên kết liên quan (docs Cloudflare) Related links (Cloudflare docs) តំណពាក់ព័ន្ធ (docs Cloudflare)

F Cài đặt gói Cloudflare f. Install the Cloudflare package អាសយដ្ឋាន ទាញយកកញ្ចប់ Cloudflare

Phần «F. Install Cloudflare package» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.

Read the "f. Install the Cloudflare package" section below — open the official docs link for full screenshots and configuration tabs.

អានផ្នែក «អាសយដ្ឋាន ទាញយកកញ្ចប់ Cloudflare» ខាងក្រោម — បើកតំណ docs ផ្លូវការសម្រាប់រូបភាព និង tab កំណត់។

Mở section docs gốc ↗ Open source section ↗ បើកផ្នែក docs ផ្លូវការ ↗
Bạn cần cài đặt gói Cloudflare cho ngôn ngữ của bạn để xác định tài nguyên Cloudflare trong chương trình Pulumi của bạn.
You need to install the Cloudflare package for your language of choice in order to define Cloudflare resources in your Pulumi program.
អ្នកត្រូវការដំឡើងកញ្ចប់ Cloudflare សម្រាប់ភាសាដែលអ្នកជ្រើសរើសដើម្បីបញ្ជាក់ថាមពល Cloudflare ក្នុងកម្មវិធី Pulumi របស់អ្នក។
Cài đặt gói Cloudflare bằng cách chạy lệnh sau:
Install the Cloudflare package by running the following command:
ការដំឡើងកញ្ចប់ Cloudflare ដោយធ្វើការបញ្ជាបញ្ជាខាងក្រោមនេះ:
Cửa sổ Terminal
Terminal window
បង្វិល Terminal
text
npm install @pulumi/cloudflare
text
added 1 package ...
Cửa sổ Terminal
Terminal window
បង្វិល Terminal
text
npm install @pulumi/cloudflare
text
added 1 package ...
Cửa sổ Terminal
Terminal window
បង្វិល Terminal
text
echo "pulumi_cloudflare>=5.38,<6.0.0" >> requirements.txt

source venv/bin/activate

pip install -r requirements.txt
text
...Collecting pulumi-cloudflare...
Cửa sổ Terminal
Terminal window
បង្វិល Terminal
text
go get github.com/pulumi/pulumi-cloudflare/sdk/v3/go/cloudflare
text
go: downloading github.com/pulumi/pulumi-cloudflare ...
Dưới đây là hướng dẫn của Apache Maven. Đối với các quản lý dự án Java khác như Gradle, hãy xem Maven repository ↗ chính thức
Below are Apache Maven instructions. For other Java project managers such as Gradle, see the official Maven repository ↗
ខាងក្រោមនេះគឺជាសំណួររបស់ Apache Maven ។ សម្រាប់អ្នកគ្រប់គ្រងគម្រោង Java ផ្សេងទៀតដូចជា Gradle សូមមើល Maven repository ↗ ។
  1. Mở tệp pom.xml của bạn.
  2. Thêm sự phụ thuộc Pulumi Cloudflare bên trong phần <dependencies>.
  1. Open your pom.xml file.
  2. Add the Pulumi Cloudflare dependency inside the <dependencies> section.
  1. សូមបើកឯកសារ pom.xml របស់អ្នក។
  2. បន្ថែមប្រព័ន្ធ Pulumi Cloudflare នៅក្នុងផ្នែក <dependencies> ។
text
<dependency>

    <groupId>com.pulumi</groupId>

    <artifactId>cloudflare</artifactId>

    <version>5.38.0</version>

</dependency>
  1. chạy đua:
  1. Run:
  1. ការធ្វើដំណើរ:
Cửa sổ Terminal
Terminal window
បង្វិល Terminal
text
mvn clean install
text
...[INFO] BUILD SUCCESS...
Cửa sổ Terminal
Terminal window
បង្វិល Terminal
text
dotnet add package Pulumi.Cloudflare
text
...

info : Adding PackageReference for package 'Pulumi.Cloudflare' into project

...
Không có phụ thuộc để tải về cho YAML. tàu phía trước.
There are no dependencies to download for YAML. Skip ahead.
គ្មានការទាញយកគោលបំណងសម្រាប់ YAML ។ សាកលវិទ្យាល័យផ្នែកខាងមុខ

2.Đối với Xác định Cloudflare tài nguyên trong mã 2. Define Cloudflare resources in code 2 ។ ការកំណត់ Cloudflare ឧបករណ៍នៅក្នុងកូដ

Phần «Define Cloudflare resources in code» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.

Read the "2. Define Cloudflare resources in code" section below — open the official docs link for full screenshots and configuration tabs.

អានផ្នែក «2 ។ ការកំណត់ Cloudflare ឧបករណ៍នៅក្នុងកូដ» ខាងក្រោម — បើកតំណ docs ផ្លូវការសម្រាប់រូបភាព និង tab កំណត់។

Mở section docs gốc ↗ Open source section ↗ បើកផ្នែក docs ផ្លូវការ ↗
Với gói Cloudflare được cài đặt, bây giờ bạn có thể xác định bất kỳ supported Cloudflare resource ↗ nào trong chương trình Pulumi của bạn. Tiếp theo, xác định một Worker, một Route, và một DNS Record.
With the Cloudflare package installed, you can now define any supported Cloudflare resource ↗ in your Pulumi program. Next, define a Worker, a Route, and a DNS Record.
ជាមួយនឹងកញ្ចប់ Cloudflare ត្រូវបានដំឡើងអ្នកអាចបញ្ជាក់ supported Cloudflare resource ↗ ទាំងអស់នៅក្នុងកម្មវិធី Pulumi របស់អ្នក។ បន្ទាប់មកកំណត់បុគ្គលិករដូវរដូវរដូវរដូវរដូវរដូវរដូវរដូវរដូវរដូវរដូវរដូវរដូវរដូវរដូវរដូវរដូវរដូវរដូវរដូវរដូវរដូវរដូវរដូវរដូវរដូវ DNS

A ơi Thêm kịch bản Workers a. Add a Workers script A ។ បន្ថែមសៀវភៅ Workers

Phần «. Add Workers script» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.

Read the "a. Add a Workers script" section below — open the official docs link for full screenshots and configuration tabs.

អានផ្នែក «A ។ បន្ថែមសៀវភៅ Workers» ខាងក្រោម — បើកតំណ docs ផ្លូវការសម្រាប់រូបភាព និង tab កំណត់។

Mở section docs gốc ↗ Open source section ↗ បើកផ្នែក docs ផ្លូវការ ↗
Workers Script resource ↗ đại diện cho một Cloudflare Worker có thể được triển khai vào mạng Cloudflare.
The Workers Script resource ↗ represents a Cloudflare Worker that can be deployed to the Cloudflare network.
Workers Script resource ↗ បានបង្ហាញនូវ Cloudflare Worker ដែលអាចត្រូវបានដំឡើងទៅលើបណ្តាញ Cloudflare ។
Thay thế nội dung của file entrypoint của bạn bằng những điều sau đây:
Replace the contents of your entrypoint file with the following:
ការផ្លាស់ប្តូរសម្ភារៈនៃឯកសារ entrypoint របស់អ្នកដោយដូចខាងក្រោម:
Filename: index.js
Filename: index.js
Filename: index.js
JavaScript Đánh giá
JavaScript
កុំព្យូទ័រ
text
"use strict";

const pulumi = require("@pulumi/pulumi");

const cloudflare = require("@pulumi/cloudflare");


const config = new pulumi.Config();

const accountId = config.require("accountId");

const domain = config.require("domain");


const content = `export default {

  async fetch(request) {

    const options = { headers: { 'content-type': 'text/plain' } };

    return new Response("Hello World!", options);

  },

};`;


const worker = new cloudflare.WorkersScript("hello-world-worker", {

  accountId: accountId,

  name: "hello-world-worker",

  content: content,

  module: true, // ES6 module

});
Filename: index.ts
Filename: index.ts
Filename: index.ts
TypeScript Đánh giá
TypeScript
កុំព្យូទ័រ
text
import * as pulumi from "@pulumi/pulumi";

import * as cloudflare from "@pulumi/cloudflare";


const config = new pulumi.Config();

const accountId = config.require("accountId");

const domain = config.require("domain");


const content = `export default {

  async fetch(request) {

    const options = { headers: { 'content-type': 'text/plain' } };

    return new Response("Hello World!", options);

  },

};`;


const worker = new cloudflare.WorkersScript("hello-world-worker", {

  accountId: accountId,

  name: "hello-world-worker",

  content: content,

  module: true, // ES6 module

});
Filename: _<em>main</em>_.py
Filename: _<em>main</em>_.py
Filename: _<em>main</em>_.py
Python
Python
Python
text
"""Pulumi program """

import pulumi

import pulumi_cloudflare as cloudflare


CONFIG = pulumi.Config()

ACCOUNT_ID = CONFIG.get("accountId")

DOMAIN = CONFIG.require("domain")

CONTENT = """

export default {

  async fetch(request) {

    const options = { headers: { 'content-type': 'text/plain' } };

    return new Response("Hello World!", options);

  },

};

"""


worker = cloudflare.WorkersScript("hello-world-worker",

    account_id=ACCOUNT_ID,

    name="hello-world-worker",

    content=CONTENT,

    module=True  # ES6 module

)
Filename: main.go
Filename: main.go
Filename: main.go
text
package main


import (

  "github.com/pulumi/pulumi-cloudflare/sdk/v5/go/cloudflare"

  "github.com/pulumi/pulumi/sdk/v3/go/pulumi"

  "github.com/pulumi/pulumi/sdk/v3/go/pulumi/config"

)


func main() {

  pulumi.Run(func(ctx *pulumi.Context) error {

    conf := config.New(ctx, "")

    accountID := conf.Get("accountId")

    domain := conf.Get("domain")

    content := `

    export default {

      async fetch(request) {

        const options = { headers: { 'content-type': 'text/plain' } };

        return new Response("Hello World!", options);

      },

    };

    `

    worker, err := cloudflare.NewWorkersScript(ctx, "hello-world-worker", &cloudflare.WorkersScriptArgs{

      AccountId: pulumi.String(accountID),

      Name:      pulumi.String("hello-world-worker"),

      Content:   pulumi.String(content),

      Module:    pulumi.Bool(true), // ES6 module

    })

    if err != nil {

      return err

    }


    return nil

  })

}
Filename: src/main/java/myproject/App.java
Filename: src/main/java/myproject/App.java
Filename: src/main/java/myproject/App.java
text
package myproject;


import com.pulumi.Pulumi;

import com.pulumi.cloudflare.WorkersScript;

import com.pulumi.cloudflare.WorkersScriptArgs;

import com.pulumi.core.Output;


public class App {

    public static void main(String[] args) {

        Pulumi.run(ctx -> {

            var content = """

              export default {

                async fetch(request) {

                  const options = { headers: { 'content-type': 'text/plain' } };

                  return new Response("Hello World!", options);

                },

              };

            """;


            var accountId = ctx.config().require("accountId");

            var domain = ctx.config().require("domain");

            var worker = new WorkersScript("hello-world-worker", WorkersScriptArgs.builder()

                .accountId(accountId)

                .name("hello-world-worker")

                .content(content)

                .module(true)

                .build());


            return;

        });

    }

}
Filename: Program.cs
Filename: Program.cs
Filename: Program.cs
text
using Pulumi;

using Cloudflare = Pulumi.Cloudflare;


return await Deployment.RunAsync(() =>

{

    var config = new Config();

    var accountId = config.Require("accountId");

    var domain = config.Require("domain");

    var content = @"

            export default {

                async fetch(request) {

                    const options = { headers: { 'content-type': 'text/plain' } };

                    return new Response(""Hello World!"", options);

                },

            };

        ";


    var worker = new Cloudflare.WorkersScript("hello-world-worker", new()

    {

        AccountId = accountId,

        Name = "hello-world-worker",

        Content = content,

        Module = true

    });

    return;

});
Filename: Pulumi.yaml
Filename: Pulumi.yaml
Filename: Pulumi.yaml
YAML
YAML
YAML
text
name: serverless-cloudflare

runtime: yaml

resources:

  worker:

    type: cloudflare:WorkersScript

    properties:

      accountId: "${accountId}"

      name: "hello-world-worker"

      content: |

        export default {

            async fetch(request) {

                const options = { headers: { 'content-type': 'text/plain' } };

                return new Response("Hello World!", options);

            },

        };

      module: true

B . Thêm một đường b. Add a Route B ។ បញ្ចូលដំណើរការ

Phần «B. Add Route» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.

Read the "b. Add a Route" section below — open the official docs link for full screenshots and configuration tabs.

អានផ្នែក «B ។ បញ្ចូលដំណើរការ» ខាងក្រោម — បើកតំណ docs ផ្លូវការសម្រាប់រូបភាព និង tab កំណត់។

Mở section docs gốc ↗ Open source section ↗ បើកផ្នែក docs ផ្លូវការ ↗
Bây giờ bạn sẽ thêm Workers Route resource ↗ vào chương trình Pulumi của bạn để kịch bản Workers có thể có điểm cuối và hoạt động. Để cấu hình đúng tuyến đường, bạn cũng sẽ tìm kiếm ID khu vực cho tên miền của bạn.
You will now add a Workers Route resource ↗ to your Pulumi program so the Workers script can have an endpoint and be active. To properly configure the Route, you will also look up the zone ID for your domain.
ឥឡូវនេះអ្នកនឹងបន្ថែម Workers Route resource ↗ ទៅកម្មវិធី Pulumi របស់អ្នកដូច្នេះ Workers សៀវភៅអាចមានទីបញ្ចប់និងមានប្រសិទ្ធិភាព។ ដើម្បីកំណត់ដំណើរការត្រឹមត្រូវអ្នកនឹងស្វែងរក ID តំបន់សម្រាប់តំបន់របស់អ្នកផងដែរ។
Thêm đoạn mã sau vào tệp entrypoint của bạn after vào tài nguyên Worker script:
Add the following code snippet to your entrypoint file after the Worker script resource:
បន្ថែមកំណត់កូដដូចខាងក្រោមដើម្បីឯកសារ entrypoint របស់អ្នក after កំណត់សៀវភៅ Worker:
Filename: index.js
Filename: index.js
Filename: index.js
JavaScript Đánh giá
JavaScript
កុំព្យូទ័រ
text
const zone = cloudflare.getZone({

  accountId: accountId,

  name: domain,

});


const zoneId = zone.then((z) => z.zoneId);


const route = new cloudflare.WorkersRoute("hello-world-route", {

  zoneId: zoneId,

  pattern: "hello-world." + domain,

  scriptName: worker.name,

});
Filename: index.ts
Filename: index.ts
Filename: index.ts
TypeScript Đánh giá
TypeScript
កុំព្យូទ័រ
text
const zone = cloudflare.getZone({

  accountId: accountId,

  name: domain,

});


const zoneId = zone.then((z) => z.zoneId);


const route = new cloudflare.WorkersRoute("hello-world-route", {

  zoneId: zoneId,

  pattern: "hello-world." + domain,

  scriptName: worker.name,

});
Filename: _<em>main</em>_.py
Filename: _<em>main</em>_.py
Filename: _<em>main</em>_.py
Python
Python
Python
text
zone = cloudflare.get_zone(account_id=ACCOUNT_ID, name=DOMAIN)

zone_id = zone.zone_id

route = cloudflare.WorkersRoute("hello-world-route",

    zone_id=zone_id,

    pattern="hello-world." + DOMAIN,

    script_name=worker.name

)
Filename: main.go
Filename: main.go
Filename: main.go
text
zone, err := cloudflare.LookupZone(ctx, &cloudflare.LookupZoneArgs{

  AccountId: &accountID,

  Name:      &domain,

}, nil)

if err != nil {

  return err

}


route, err := cloudflare.NewWorkersRoute(ctx, "hello-world-route", &cloudflare.WorkersRouteArgs{

  ZoneId:     pulumi.String(zone.Id),

  Pattern:    pulumi.String("hello-world." + domain),

  ScriptName: worker.Name,

})

if err != nil {

  return err

}
Filename: src/main/java/myproject/App.java
Filename: src/main/java/myproject/App.java
Filename: src/main/java/myproject/App.java
text
final var zone = CloudflareFunctions.getZone(GetZoneArgs.builder()

  .accountId(accountId)

  .name(domain)

  .build());

var route = new WorkersRoute("hello-world-route", WorkersRouteArgs.builder()

  .zoneId(zone.applyValue(getZoneResult -> getZoneResult.id()))

  .pattern("hello-world." + domain)

  .scriptName(worker.name())

  .build());
Filename: Program.cs
Filename: Program.cs
Filename: Program.cs
text
var zone = Output.Create(Cloudflare.GetZone.InvokeAsync(new()

{

    AccountId = accountId,

    Name = domain,

}));

var route = new Cloudflare.WorkersRoute("hello-world-route", new()

{

    ZoneId = zone.Apply(z => z.Id),

    Pattern = "hello-world." + domain,

    ScriptName = worker.Name,

});
Filename: Pulumi.yaml
Filename: Pulumi.yaml
Filename: Pulumi.yaml
Dưới phím runtime, hãy thêm mã sau:
Below the runtime key, add the following code:
នៅក្រោមគោលបំណង runtime បន្ថែមលេខកូដដូចខាងក្រោម:
YAML
YAML
YAML
text
# new top-level section

variables:

  zone:

    fn::invoke:

      function: cloudflare:getZone

      arguments:

        accountId: ${accountId}

        name: ${domain}
Dưới tài nguyên worker, hãy thêm mã sau:
Below the worker resource, add the following code:
នៅក្រោមប្រភព worker បន្ថែមលេខកូដដូចខាងក្រោម:
YAML
YAML
YAML
text
route:

  type: cloudflare:WorkersRoute

  properties:

    zoneId: ${zone.id}

    pattern: "hello-world.${domain}"

    scriptName: ${worker.name}

C . Thêm một DNS Record c. Add a DNS Record C ។ បន្ថែម DNS សៀវភៅ

Phần «C. Add DNS Record» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.

Read the "c. Add a DNS Record" section below — open the official docs link for full screenshots and configuration tabs.

អានផ្នែក «C ។ បន្ថែម DNS សៀវភៅ» ខាងក្រោម — បើកតំណ docs ផ្លូវការសម្រាប់រូបភាព និង tab កំណត់។

Mở section docs gốc ↗ Open source section ↗ បើកផ្នែក docs ផ្លូវការ ↗
Bây giờ bạn sẽ thêm DNS Record resource ↗ để giải quyết Route được cấu hình trước đó. Trong bước tiếp theo, bạn cũng sẽ đầu ra URL Route để nó có thể dễ dàng truy cập.
You will now add a DNS Record resource ↗ to resolve the previously configured Route. In the next step, you'll also output the Route URL so it can be easily accessed.
ឥឡូវនេះអ្នកនឹងបន្ថែម DNS Record resource ↗ ដើម្បីដោះស្រាយដំណើរការដែលបានកំណត់មុន។ ក្នុងដំណោះស្រាយបន្ទាប់អ្នកនឹងនាំចេញ URL Route ដូច្នេះវាអាចចូលបានយ៉ាងងាយស្រួល។
Thêm đoạn mã sau vào tệp entrypoint của bạn after vào tài nguyên Route:
Add the following code snippet to your entrypoint file after the Route resource:
បន្ថែមកូដខាងក្រោមទៅឯកសារចំណុចបញ្ចូលរបស់អ្នក after កុំព្យូទ័រ Route:
Filename: index.js
Filename: index.js
Filename: index.js
JavaScript Đánh giá
JavaScript
កុំព្យូទ័រ
text
const record = new cloudflare.Record("hello-world-record", {

  name: route.pattern,

  type: "A",

  content: "192.0.2.1",

  zoneId: zoneId,

  proxied: true,

});


exports.url = pulumi.interpolate`https://${record.hostname}`;
Filename: index.ts
Filename: index.ts
Filename: index.ts
TypeScript Đánh giá
TypeScript
កុំព្យូទ័រ
text
const record = new cloudflare.Record("hello-world-record", {

  name: route.pattern,

  type: "A",

  content: "192.0.2.1",

  zoneId: zoneId,

  proxied: true,

});


export const url = pulumi.interpolate`https://${record.hostname}`;
Filename: _<em>main</em>_.py
Filename: _<em>main</em>_.py
Filename: _<em>main</em>_.py
Python
Python
Python
text
record = cloudflare.Record("hello-world-record",

    name=route.pattern,

    type="A",

    content="192.0.2.1",

    zone_id=zone_id,

    proxied=True

)


url = pulumi.Output.concat("https://", record.hostname)

pulumi.export('url', url)
Filename: main.go
Filename: main.go
Filename: main.go
text
record, err := cloudflare.NewRecord(ctx, "hello-world-record", &cloudflare.RecordArgs{

  Name:    route.Pattern,

  Type:    pulumi.String("A"),

  Content: pulumi.String("192.0.2.1"),

  ZoneId:  pulumi.String(zone.Id),

  Proxied: pulumi.Bool(true),

})

if err != nil {

  return err

}


ctx.Export("url", pulumi.Sprintf("https://%s", record.Hostname))
Filename: src/main/java/myproject/App.java
Filename: src/main/java/myproject/App.java
Filename: src/main/java/myproject/App.java
text
var record = new Record("hello-world-record", RecordArgs.builder()

    .name(route.pattern())

    .type("A")

    .content("192.0.2.1")

    .zoneId(zone.applyValue(getZoneResult -> getZoneResult.id()))

    .proxied(true)

    .build());


ctx.export("url", Output.format("https://%s", record.hostname()));
Filename: Program.cs
Filename: Program.cs
Filename: Program.cs
Lưu ý rằng cụm từ "trả về" đã được cập nhật vì bạn hiện đang xuất một giá trị. Đảm bảo rằng bạn cũng bao gồm using System.Collections.Generic; trong nhập khẩu của bạn.
Notice the updated ' return ' statement because you're now exporting a value. Ensure that you also include using System.Collections.Generic; in your imports.
សូមពិនិត្យមើលការបង្ហាញ "ការបង្ហាញ" ដែលបានបច្ចុប្បន្នដោយសារតែអ្នកកំពុងនាំចេញតម្លៃ។ សូមប្រាកដថាអ្នកក៏មាន using System.Collections.Generic; នៅក្នុងការនាំចូលរបស់អ្នក។
text
var record = new Cloudflare.Record("hello-world-record", new()

{

    Name = route.Pattern,

    Type = "A",

    Content = "192.0.2.1",

    ZoneId = zone.Apply(z => z.Id),

    Proxied = true

});


return new Dictionary<string, object?>

{

    ["url"] = Output.Format($"https://{record.Hostname}")

};
Chú ý đến phần outputs cấp cao mới.
Notice the new top-level outputs section.
សូមមើលកំណត់ outputs នៃកម្រិតខ្ពស់ថ្មី។
YAML
YAML
YAML
text
record:

    type: cloudflare:Record

    properties:

      name: ${route.pattern}

      type: A

      content: "192.0.2.1"

      zoneId: ${zone.id}

      proxied: true


outputs:

  url: "https://${record.hostname}"
Bạn có thể cần sử dụng http thay vào đó tùy thuộc vào cài đặt tên miền của bạn.
You may need to use http instead depending on your domain settings.
អ្នកអាចប្រើ http ដោយផ្អែកលើការកំណត់តំបន់របស់អ្នក។

D . (Tùy chọn) Xác minh mã của bạn d. (Optional) Verify your code លោក D ។ (តម្រូវការ) ពិនិត្យឡើងវិញកូដរបស់អ្នក

Phần «d. (Optional) Verify your code» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.

Read the "d. (Optional) Verify your code" section below — open the official docs link for full screenshots and configuration tabs.

អានផ្នែក «លោក D ។ (តម្រូវការ) ពិនិត្យឡើងវិញកូដរបស់អ្នក» ខាងក្រោម — បើកតំណ docs ផ្លូវការសម្រាប់រូបភាព និង tab កំណត់។

Mở section docs gốc ↗ Open source section ↗ បើកផ្នែក docs ផ្លូវការ ↗
Xác nhận tất cả các thay đổi của bạn phù hợp với giải pháp đầy đủ dưới đây:
Confirm all your changes match the full solution below:
សូមបញ្ជាក់ថាតើការផ្លាស់ប្តូរទាំងអស់របស់អ្នកត្រឹមត្រូវទៅនឹងដំណោះស្រាយពេញលេញខាងក្រោម:
Filename: index.js
Filename: index.js
Filename: index.js
JavaScript Đánh giá
JavaScript
កុំព្យូទ័រ
text
"use strict";

const pulumi = require("@pulumi/pulumi");

const cloudflare = require("@pulumi/cloudflare");


const config = new pulumi.Config();

const accountId = config.require("accountId");

const domain = config.require("domain");


const content = `export default {

  async fetch(request) {

    const options = { headers: { 'content-type': 'text/plain' } };

    return new Response("Hello World!", options);

  },

};`;


const worker = new cloudflare.WorkersScript("hello-world-worker", {

  accountId: accountId,

  name: "hello-world-worker",

  content: content,

  module: true, // ES6 module

});


const zone = cloudflare.getZone({

  accountId: accountId,

  name: domain,

});


const zoneId = zone.then((z) => z.zoneId);


const route = new cloudflare.WorkersRoute("hello-world-route", {

  zoneId: zoneId,

  pattern: "hello-world." + domain,

  scriptName: worker.name,

});


const record = new cloudflare.Record("hello-world-record", {

  name: route.pattern,

  type: "A",

  content: "192.0.2.1",

  zoneId: zoneId,

  proxied: true,

});


exports.url = pulumi.interpolate`https://${record.hostname}`;
Filename: index.ts
Filename: index.ts
Filename: index.ts
TypeScript Đánh giá
TypeScript
កុំព្យូទ័រ
text
import * as pulumi from "@pulumi/pulumi";

import * as cloudflare from "@pulumi/cloudflare";


const config = new pulumi.Config();

const accountId = config.require("accountId");

const domain = config.require("domain");


const content = `export default {

  async fetch(request) {

    const options = { headers: { 'content-type': 'text/plain' } };

    return new Response("Hello World!", options);

  },

};`;


const worker = new cloudflare.WorkersScript("hello-world-worker", {

  accountId: accountId,

  name: "hello-world-worker",

  content: content,

  module: true, // ES6 module

});


const zone = cloudflare.getZone({

  accountId: accountId,

  name: domain,

});


const zoneId = zone.then((z) => z.zoneId);


const route = new cloudflare.WorkersRoute("hello-world-route", {

  zoneId: zoneId,

  pattern: "hello-world." + domain,

  scriptName: worker.name,

});


const record = new cloudflare.Record("hello-world-record", {

  name: route.pattern,

  type: "A",

  content: "192.0.2.1",

  zoneId: zoneId,

  proxied: true,

});


export const url = pulumi.interpolate`https://${record.hostname}`;
Filename: _<em>main</em>_.py
Filename: _<em>main</em>_.py
Filename: _<em>main</em>_.py
Python
Python
Python
text
"""Pulumi program """

import pulumi

import pulumi_cloudflare as cloudflare


CONFIG = pulumi.Config()

ACCOUNT_ID = CONFIG.get("accountId")

DOMAIN = CONFIG.require("domain")

CONTENT = """

export default {

  async fetch(request) {

    const options = { headers: { 'content-type': 'text/plain' } };

    return new Response("Hello World!", options);

  },

};

"""


worker = cloudflare.WorkersScript("hello-world-worker",

    account_id=ACCOUNT_ID,

    name="hello-world-worker",

    content=CONTENT,

    module=True  # ES6 module

)


zone = cloudflare.get_zone(account_id=ACCOUNT_ID, name=DOMAIN)

zone_id = zone.zone_id

route = cloudflare.WorkersRoute("hello-world-route",

    zone_id=zone_id,

    pattern="hello-world." + DOMAIN,

    script_name=worker.name

)


record = cloudflare.Record("hello-world-record",

    name=route.pattern,

    type="A",

    content="192.0.2.1",

    zone_id=zone_id,

    proxied=True

)


url = pulumi.Output.concat("https://", record.hostname)

pulumi.export('url', url)
Filename: main.go
Filename: main.go
Filename: main.go
text
package main


import (

  "github.com/pulumi/pulumi-cloudflare/sdk/v5/go/cloudflare"

  "github.com/pulumi/pulumi/sdk/v3/go/pulumi"

  "github.com/pulumi/pulumi/sdk/v3/go/pulumi/config"

)


func main() {

  pulumi.Run(func(ctx *pulumi.Context) error {

    conf := config.New(ctx, "")

    accountID := conf.Get("accountId")

    domain := conf.Get("domain")

    content := `

    export default {

      async fetch(request) {

        const options = { headers: { 'content-type': 'text/plain' } };

        return new Response("Hello World!", options);

      },

    };

    `

    worker, err := cloudflare.NewWorkersScript(ctx, "hello-world-worker", &cloudflare.WorkersScriptArgs{

      AccountId: pulumi.String(accountID),

      Name:      pulumi.String("hello-world-worker"),

      Content:   pulumi.String(content),

      Module:    pulumi.Bool(true), // ES6 module

    })

    if err != nil {

      return err

    }

    zone, err := cloudflare.LookupZone(ctx, &cloudflare.LookupZoneArgs{

      AccountId: &accountID,

      Name:      &domain,

    }, nil)

    if err != nil {

      return err

    }


    route, err := cloudflare.NewWorkersRoute(ctx, "hello-world-route", &cloudflare.WorkersRouteArgs{

      ZoneId:     pulumi.String(zone.Id),

      Pattern:    pulumi.String("hello-world." + domain),

      ScriptName: worker.Name,

    })

    if err != nil {

      return err

    }


    record, err := cloudflare.NewRecord(ctx, "hello-world-record", &cloudflare.RecordArgs{

      Name:    route.Pattern,

      Type:    pulumi.String("A"),

      Content: pulumi.String("192.0.2.1"),

      ZoneId:  pulumi.String(zone.Id),

      Proxied: pulumi.Bool(true),

    })

    if err != nil {

      return err

    }


    ctx.Export("url", pulumi.Sprintf("https://%s", record.Hostname))


    return nil

  })

}
Filename: src/main/java/myproject/App.java
Filename: src/main/java/myproject/App.java
Filename: src/main/java/myproject/App.java
text
package myproject;


import com.pulumi.Pulumi;

import com.pulumi.core.Output;

import com.pulumi.cloudflare.WorkersScript;

import com.pulumi.cloudflare.WorkersScriptArgs;

import com.pulumi.cloudflare.CloudflareFunctions;

import com.pulumi.cloudflare.inputs.GetZoneArgs;

import com.pulumi.cloudflare.WorkersRoute;

import com.pulumi.cloudflare.WorkersRouteArgs;

import com.pulumi.cloudflare.Record;

import com.pulumi.cloudflare.RecordArgs;


public class App {

    public static void main(String[] args) {

        Pulumi.run(ctx -> {

            var content = """

        export default {

          async fetch(request) {

            const options = { headers: { 'content-type': 'text/plain' } };

            return new Response("Hello World!", options);

          },

        };

      """;


            var accountId = ctx.config().require("accountId");

            var domain = ctx.config().require("domain");


            var worker = new WorkersScript("hello-world-worker", WorkersScriptArgs.builder()

                .accountId(accountId)

                .name("hello-world-worker")

                .content(content)

                .module(true)

                .build());

            final var zone = CloudflareFunctions.getZone(GetZoneArgs.builder()

                .accountId(accountId)

                .name(domain)

                .build());

            var route = new WorkersRoute("hello-world-route", WorkersRouteArgs.builder()

                .zoneId(zone.applyValue(getZoneResult -> getZoneResult.id()))

                .pattern("hello-world." + domain)

                .scriptName(worker.name())

                .build());

            var record = new Record("hello-world-record", RecordArgs.builder()

                .name(route.pattern())

                .type("A")

                .content("192.0.2.1")

                .zoneId(zone.applyValue(getZoneResult -> getZoneResult.id()))

                .proxied(true)

                .build());


            ctx.export("url", Output.format("https://%s", record.hostname()));

            return;

        });

    }

}
Filename: Program.cs
Filename: Program.cs
Filename: Program.cs
text
using System.Collections.Generic;

using Pulumi;

using Cloudflare = Pulumi.Cloudflare;


return await Deployment.RunAsync(() =>

{

    var config = new Config();

    var accountId = config.Require("accountId");

    var domain = config.Require("domain");

    var content = @"

            export default {

                async fetch(request) {

                    const options = { headers: { 'content-type': 'text/plain' } };

                    return new Response(""Hello World!"", options);

                },

            };

        ";


    var worker = new Cloudflare.WorkersScript("hello-world-worker", new()

    {

        AccountId = accountId,

        Name = "hello-world-worker",

        Content = content,

        Module = true

    });

    var zone = Output.Create(Cloudflare.GetZone.InvokeAsync(new()

    {

        AccountId = accountId,

        Name = domain,

    }));

    var route = new Cloudflare.WorkersRoute("hello-world-route", new()

    {

        ZoneId = zone.Apply(z => z.Id),

        Pattern = "hello-world." + domain,

        ScriptName = worker.Name,

    });


    var record = new Cloudflare.Record("hello-world-record", new()

    {

        Name = route.Pattern,

        Type = "A",

        Content = "192.0.2.1",

        ZoneId = zone.Apply(z => z.Id),

        Proxied = true

    });


    return new Dictionary<string, object?>

    {

        ["url"] = Output.Format($"https://{record.Hostname}")

    };

});
Filename: Pulumi.yaml
Filename: Pulumi.yaml
Filename: Pulumi.yaml
YAML
YAML
YAML
text
name: serverless-cloudflare

runtime: yaml

variables:

  zone:

    fn::invoke:

      function: cloudflare:getZone

      arguments:

        accountId: ${accountId}

        name: ${domain}


resources:

  worker:

    type: cloudflare:WorkersScript

    properties:

      accountId: "${accountId}"

      name: "hello-world-worker"

      content: |

        export default {

            async fetch(request) {

                const options = { headers: { 'content-type': 'text/plain' } };

                return new Response("Hello World!", options);

            },

        };

      module: true

  route:

    type: cloudflare:WorkersRoute

    properties:

      zoneId: ${zone.id}

      pattern: "hello-world.${domain}"

      scriptName: ${worker.name}

  record:

    type: cloudflare:Record

    properties:

      name: ${route.pattern}

      type: A

      content: "192.0.2.1"

      zoneId: ${zone.id}

      proxied: true


outputs:

  url: "https://${record.hostname}"

3 Cái triển khai ứng dụng của bạn 3. Deploy your application 3 ។ ទាញយកកម្មវិធីរបស់អ្នក

Phần «Triển khai your ứng dụng» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.

Read the "3. Deploy your application" section below — open the official docs link for full screenshots and configuration tabs.

អានផ្នែក «3 ។ ទាញយកកម្មវិធីរបស់អ្នក» ខាងក្រោម — បើកតំណ docs ផ្លូវការសម្រាប់រូបភាព និង tab កំណត់។

Mở section docs gốc ↗ Open source section ↗ បើកផ្នែក docs ផ្លូវការ ↗
Bây giờ bạn đã xác định tất cả các tài nguyên Cloudflare, bạn có thể triển khai ứng dụng Hello World vào tài khoản Cloudflare của bạn bằng cách sử dụng Pulumi CLI.
Now that you have defined all the Cloudflare resources, you can deploy the Hello World application to your Cloudflare account using the Pulumi CLI.
ឥឡូវនេះដែលអ្នកបានកំណត់ថាមពលទាំងអស់ Cloudflare អ្នកអាចដំឡើងកម្មវិធី Hello World ទៅលើគណនីរបស់អ្នក Cloudflare ដោយប្រើ Pulumi CLI ។
Để triển khai các thay đổi, chạy:
To deploy the changes, run:
ដើម្បីដំឡើងការផ្លាស់ប្តូរ, Run:
Cửa sổ Terminal
Terminal window
បង្វិល Terminal
text
pulumi up --yes
text
wait for the dev stack to become ready

Bốn Kiểm tra công nhân 4. Test the Worker 4 ។ ការធ្វើតេស្តបុគ្គលិក

Phần «Test Worker» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.

Read the "4. Test the Worker" section below — open the official docs link for full screenshots and configuration tabs.

អានផ្នែក «4 ។ ការធ្វើតេស្តបុគ្គលិក» ខាងក្រោម — បើកតំណ docs ផ្លូវការសម្រាប់រូបភាព និង tab កំណត់។

Mở section docs gốc ↗ Open source section ↗ បើកផ្នែក docs ផ្លូវការ ↗
Bạn đã tăng dần Cloudflare tài nguyên để chạy và access ứng dụng của bạn Hello World. Bạn có thể kiểm tra ứng dụng của mình bằng cách cuộn đầu ra url từ khối Pulumi.
You incrementally added Cloudflare resources to run and access your Hello World application. You can test your application by curling the url output from the Pulumi stack.
អ្នកបានបន្ថែម Cloudflare សមត្ថភាពដើម្បីដំណើរការនិង access កម្មវិធីរបស់អ្នក Hello World ។ អ្នកអាចធ្វើតេស្តកម្មវិធីរបស់អ្នកដោយ curling ទិន្នផល url ពីថ្នាំ Pulumi ។
Cửa sổ Terminal
Terminal window
បង្វិល Terminal
text
curl $(pulumi stack output url)
text
Hello, World!

5 Làm sạch 5. Clean up 5 ។ ការសាងសង់

Phần «Dọn dẹp» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.

Read the "5. Clean up" section below — open the official docs link for full screenshots and configuration tabs.

អានផ្នែក «5 ។ ការសាងសង់» ខាងក្រោម — បើកតំណ docs ផ្លូវការសម្រាប់រូបភាព និង tab កំណត់។

Mở section docs gốc ↗ Open source section ↗ បើកផ្នែក docs ផ្លូវការ ↗
Trong bước cuối cùng này, bạn sẽ làm sạch các nguồn lực và stack được sử dụng trong suốt hướng dẫn.
In this last step, you will clean up the resources and stack used throughout the tutorial.
ក្នុងដំណោះស្រាយចុងក្រោយនេះអ្នកនឹងរក្សាទុកនិងដែកថែបដែលត្រូវបានប្រើនៅជុំវិញការបណ្តុះបណ្តាល។

A ơi Xóa tài nguyên Cloudflare a. Delete the Cloudflare resources A ។ ទាញយក Cloudflare

Phần «. Delete Cloudflare resources» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.

Read the "a. Delete the Cloudflare resources" section below — open the official docs link for full screenshots and configuration tabs.

អានផ្នែក «A ។ ទាញយក Cloudflare» ខាងក្រោម — បើកតំណ docs ផ្លូវការសម្រាប់រូបភាព និង tab កំណត់។

Mở section docs gốc ↗ Open source section ↗ បើកផ្នែក docs ផ្លូវការ ↗
Cửa sổ Terminal
Terminal window
បង្វិល Terminal
text
pulumi destroy

B . Loại bỏ Pulumi Stack b. Remove the Pulumi stack B ។ ទាញយក Pulumi Stack

Phần «B. Remove Pulumi stack» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.

Read the "b. Remove the Pulumi stack" section below — open the official docs link for full screenshots and configuration tabs.

អានផ្នែក «B ។ ទាញយក Pulumi Stack» ខាងក្រោម — បើកតំណ docs ផ្លូវការសម្រាប់រូបភាព និង tab កំណត់។

Mở section docs gốc ↗ Open source section ↗ បើកផ្នែក docs ផ្លូវការ ↗
Cửa sổ Terminal
Terminal window
បង្វិល Terminal
text
pulumi stack rm dev

Bước tiếp theo Next steps ជំហានបន្ទាប់

Phần «Bước tiếp theo» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.

Read the "Next steps" section below — open the official docs link for full screenshots and configuration tabs.

អានផ្នែក «ជំហានបន្ទាប់» ខាងក្រោម — បើកតំណ docs ផ្លូវការសម្រាប់រូបភាព និង tab កំណត់។

Mở section docs gốc ↗ Open source section ↗ បើកផ្នែក docs ផ្លូវការ ↗
Truy cập Cloudflare package documentation ↗ để khám phá các tài nguyên khác mà bạn có thể định nghĩa với Pulumi và Cloudflare.
Visit the Cloudflare package documentation ↗ to explore other resources you can define with Pulumi and Cloudflare.
សូមស្វែងរក Cloudflare package documentation ↗ ដើម្បីស្វែងរកសម្ភារៈផ្សេងទៀតដែលអ្នកអាចកំណត់ជាមួយ Pulumi និង Cloudflare ។
json
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"item":{"@id":"/directory/","name":"Directory"}},{"@type":"ListItem","position":2,"item":{"@id":"/pulumi/","name":"Pulumi"}},{"@type":"ListItem","position":3,"item":{"@id":"/pulumi/tutorial/","name":"Tutorials"}},{"@type":"ListItem","position":4,"item":{"@id":"/pulumi/tutorial/hello-world/","name":"Deploy a Worker"}}]}

Xem bản đầy đủ trên developers.cloudflare.com (ảnh, tab cấu hình). View the full guide on developers.cloudflare.com (images, config tabs). មើលមគ្គុទ្ទេសក៍ពេញលើ developers.cloudflare.com (រូបភាព, tab កំណត់)។

Tài liệu gốc ↗ Official docs ↗ ឯកសារផ្លូវការ ↗