DEV Community

陈杨
陈杨

Posted on

HarmonyOS5 Cloud Service Technology Sharing--Serverless Build Draw

✨[Practical Guide] A Step-by-Step Tutorial on Quickly Building a Lottery Activity with Huawei AGC Serverless Templates✨

Hi fellow developers! Today I'm sharing a super practical trick—building a lottery activity in three minutes using Huawei AppGallery Connect's (AGC) Serverless templates. No backend code, no server maintenance worries, perfect for those who want to launch operational activities quickly~ Let's see how it's done!

💡 I. Preparations (Key Points!)

1️⃣ Create a Project Foundation:

  • Log in to the AGC console to create a new project (skip if you already have one)
  • Complete initialization configuration in the "Cloud Development > Serverless" module

2️⃣ Remember Security Configurations:

  • Get application SDK information (Path: Project settings > App information)
  • Important Note❗Do not write agConnectConfig directly into a JS file. It is recommended to encrypt and store it, then inject it into the Window object before the H5 page loads to prevent information leakage.

3️⃣ Prepare Callback Functions in Advance:

  • Create two new functions in the Cloud Functions module:
    • Start lottery callback function (e.g., name it startDraw)
    • End lottery callback function (e.g., name it finishDraw)
  • Note down the function names for later use (needed for parameter configuration).

🎯 II. Three-Step Deployment (Just Follow Along)

Step 1️⃣ Template Selection

  • Go to the Serverless Template Library → Find the "Lottery Activity" template
  • Click the "Deploy" button → Select the target project (Note: Currently only supports data processing in the China region)

Step 2️⃣ Parameter Configuration (The Core Part!)

Parameter Configuration Description
Authentication-free Select "No" to fill in the authentication callback URL; select "Yes" for users to draw without logging in
Authentication Callback URL The address on the developer's server that receives authentication requests (you need to implement an interface to get the user ID yourself)
Custom Configuration Configuration in JSON format, e.g., { "showPopup":true, "beginCallback":"startDraw", "endCallback":"finishDraw" }

Step 3️⃣ One-Click Deployment

  • After clicking "Start Deployment," grab a coffee☕ (usually completes in 1-3 minutes)
  • Don't panic if deployment fails! You can provide feedback in the interactive center or submit a ticket. Huawei engineers will respond within 1-3 working days.

🚀 III. Hosting and Go-Live (Making it Accessible to Users)

1️⃣ Project Package Handling:

  • Modify the function names in the portal/dist/function.js file (corresponding to the cloud functions created earlier)
  • Compress the contents of the dist folder into dist.zip (Note❗Select the files and then compress, don't compress the folder directly)

2️⃣ Cloud Hosting Configuration:

  • Go to Cloud Hosting → Enable the web hosting service
  • Create a site → Upload dist.zip → Wait for the status to become "Online"
  • Tip: Use browser developer tools to adjust H5 styles for responsiveness.

🎁 IV. Must-See Tips for Operations Experts

✅ Customization Secrets:

  • You can modify the CSS/HTML in the project package to customize the interface
  • Control the prize-winning pop-up by modifying the showPopup parameter
  • Integrate a points system or prize-awarding logic in the callback functions

⚠️ Pitfall Guide:

  • The compressed package must contain index.html in the root directory
  • The total file size should not exceed 400MB
  • If you encounter CORS issues, check the callback URL configuration
  • It's recommended to enable authentication-free mode during the testing phase

💬 Common QA:

Q: What application types are supported?

A: Currently, it supports Web applications and APKs (both Android/iOS are OK).

Q: Can I integrate it with my own user system?

A: Of course! Integrate it via the authentication callback URL, and remember to return a unique user ID.

Q: How can I view the activity data?

A: You can view the lottery records in the Cloud DB for Object module.

✨【Full Process Summary】

After reading this guide, do you find that building a lottery activity is simpler than you imagined? With Huawei AGC's Serverless templates, it's just a three-step process from configuration to launch: "Select Template → Configure Parameters → Host & Deploy." No need to worry about backend logic at all! Whether for e-commerce promotions, game operations, or community events, this solution can be implemented quickly.

💡 Final Reminders:

  • During the testing phase, it's recommended to first run through the process using "Authentication-Free Mode."
  • Before going live, be sure to check the security of the callback functions (e.g., anti-fraud mechanisms).
  • If you encounter technical problems, feel free to reach out to the "Developer Community" or submit a support ticket.

Open the AGC console and try it out now! If you have other creative ideas, feel free to discuss them in the comments section~ We'll be sharing more practical Serverless tips in the future, so be sure to follow! 🚀

(End of text)

Top comments (0)