You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
updated: tutorial prerequisites and steps for geospatial hotel search implementation
- Updated prerequisites to include specific Couchbase and AWS account requirements
- Revised tutorial steps for creating AppSync API and configuring Data API
- Updated screenshots and interactive map descriptions for better user guidance
Copy file name to clipboardExpand all lines: tutorial/markdown/nodejs/dataApi-appsync-tutorial/tutorial.md
+50-18Lines changed: 50 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -32,19 +32,26 @@ If you want to see the final code you can refer to it here: [Final Demo Code](ht
32
32
This guide walks you through building a geospatial hotel search demo that finds hotels within a specified distance from airports. The application uses AWS AppSync (GraphQL) with environment variables for credential management, Couchbase Data API for executing SQL++ queries, and a Streamlit frontend for interactive map visualization — end to end, with inlined code.
33
33
34
34
### Prerequisites
35
-
- Couchbase Capella account with the Travel Sample dataset loaded and credentials that can access it (and network access allowed).
36
-
- Learn/setup here: [Couchbase Data API Prerequisites](https://docs.couchbase.com/cloud/data-api-guide/data-api-start.html#prerequisites)
37
-
- Couchbase Data API docs (enable Data API, copy endpoint)
38
-
-[Data API Docs](https://docs.couchbase.com/cloud/data-api-guide/data-api-start.html)
35
+
-**[Couchbase Capella account](https://cloud.couchbase.com/sign-up)** with a [running cluster](https://docs.couchbase.com/cloud/get-started/create-account.html)
36
+
-**[Travel-sample bucket](https://docs.couchbase.com/cloud/clusters/data-service/import-data-documents.html)** imported into your cluster
37
+
-**[Data API enabled](https://docs.couchbase.com/cloud/data-api-guide/data-api-start.html)** in Capella (via the cluster's Connect page)
38
+
-**Important:** Set Allowed IP address to **"Allow access from anywhere"** for demo purposes
39
+
- This configuration is required for this demo to function with AWS AppSync
40
+
- Not recommended for production—see [documentation](https://docs.couchbase.com/cloud/data-api-guide/data-api-start.html) for secure network configurations
41
+
-**[AWS account](https://aws.amazon.com/)** with permissions to create AppSync APIs
39
42
40
43
---
41
44
42
45
### Enable Couchbase Data API
43
46
44
47
**What is Data API?**
45
48
Couchbase Data API provides a RESTful HTTP interface to your cluster. Instead of embedding the Couchbase SDK in your app, you make standard HTTP requests to query, insert, or update documents. This is perfect for serverless architectures (like AppSync) because:
46
-
- No heavy SDK initialization on cold starts
47
-
- Works from any language with HTTP support
49
+
-**Enables driverless mode:** No need to deploy SDKs in FaaS environments (AWS Lambda, Azure Functions)
50
+
-**Is lightweight:** Avoids heavy SDK initialization overhead in stateless functions
51
+
-**Simplifies integration:** Uses standard HTTP—no SDK version management or dependencies
52
+
-**Is language agnostic:** Works with any platform that can make HTTP requests
53
+
54
+
Learn more: [Data API vs. SDKs](https://docs.couchbase.com/cloud/data-api-guide/data-api-sdks.html)
48
55
49
56
**Steps:**
50
57
1. In Capella, enable Data API for your project/cluster (single click in the cluster settings).
@@ -68,7 +75,9 @@ Couchbase Data API provides a RESTful HTTP interface to your cluster. Instead of
68
75
AppSync provides a managed GraphQL layer with built-in auth, and logging. It lets your frontend speak GraphQL while your backend (Data API) speaks SQL++. The resolver bridges the two.
69
76
70
77
**Steps:**
71
-
1. Create an AppSync GraphQL API with Public API (we'll use API key auth for demo simplicity).
78
+
1. Create an AppSync GraphQL API:
79
+
- Choose **"Build from scratch"** option when prompted
80
+
- Select **Public API** with **API key** authentication for demo simplicity
72
81
73
82
#### Define the schema (paste into the schema editor)
74
83
@@ -162,7 +171,7 @@ AppSync can call external HTTP APIs. You configure a base URL (your Data API end
162
171
**Steps:**
163
172
- In AppSync, create a new HTTP data source.
164
173
- Set the endpoint to your Couchbase Data API base URL (from step 1).
165
-
-**Do not**configure auth here; we'll add Basic auth dynamically in the resolver using credentials from environment variables.
174
+
-**Important:**Do NOT enable "Authorization configuration", since credentials will be passed dynamically via the resolver using AppSync environment variables.
166
175
167
176
#### Screenshot
168
177

@@ -186,7 +195,7 @@ These environment variables will be accessible in your resolvers via `ctx.env.cb
- Returns both hotels and airport information in the `Output` schema format.
205
214
206
215
**Why `query_context`?**
207
216
Setting `query_context` to `default:travel-sample.inventory` lets you write `FROM hotel` instead of the fully qualified `FROM travel-sample.inventory.hotel` in your SQL++. It's a namespace shortcut.
3. Click **Run**. You should see a JSON response with:
401
-
- An array of hotels within 50km of Heathrow airport
410
+
- An array of hotels within 50km of Les Loges airport
402
411
- Airport information including name and location coordinates
403
412
404
-
Try different airport names like "Charles de Gaulle", or "Changi" to see results from different locations.
413
+
Try different airport names like **"San Francisco Intl"**, **"Charles de Gaulle"**, **"Luton"**, or **"London St Pancras"** to see results from different locations.
414
+
415
+
**Troubleshooting:** If you encounter a "connection timed out" error, verify that your Data API has IP address access set to **"Allow access from anywhere"** in the Capella Connect page (see Prerequisites section). This is required for AWS AppSync to reach your cluster.
405
416
406
417
If it works, you've successfully bridged AppSync → Data API → Couchbase with geospatial querying!
407
418
@@ -415,17 +426,38 @@ Now that you've set up your AWS AppSync backend with the Couchbase Data API inte
415
426
416
427
Visit the live Streamlit app at **[https://couchbase-data-api-appsync-demo.streamlit.app/](https://couchbase-data-api-appsync-demo.streamlit.app/)**
417
428
418
-
The app provides an interactive map-based interface where you can search for hotels near airports. Simply enter your AppSync GraphQL endpoint and API key in the sidebar (note that Couchbase credentials are securely stored as environment variables in AppSync, so you don't need to enter them). Navigate to "Search Hotels", enter an airport name like **"Les Loges"**and a distance like **100 km**, then click "Search".
429
+
The app provides an interactive map-based interface where you can search for hotels near airports. Simply enter your **AppSync GraphQL Endpoint** and **AppSync API Key** in the sidebar (note that Couchbase credentials are securely stored as environment variables in AppSync, so you don't need to enter them). Click the **"Search Hotels"** tab, enter an airport name like **"San Francisco Intl"**, **"Les Loges"**, **"Luton"**, or **"London St Pancras"**and a distance like **100 km**, then click "Search". A loading spinner will appear while fetching results.
419
430
420
431
Results display on an interactive map with the airport shown as an orange marker and hotels as color-coded dots (green for excellent ratings, red for poor). The map automatically centers on the airport location. Hover over any marker to see details like hotel names, addresses, prices, and phone numbers, or expand the "Raw response" section to see the full JSON data from AppSync.

425
436
426
-
**Want to explore the source code or run it locally?** The complete Streamlit frontend code is available at [https://github.com/couchbase-examples/couchbase-data_api-appsync-demo/tree/main/src/frontend](https://github.com/couchbase-examples/couchbase-data_api-appsync-demo/tree/main/src/frontend). The frontend consists of `home.py` (navigation and connection settings) and `search_hotels.py` (hotel search with map visualization using `pydeck`). It uses the `requests` library to call AppSync GraphQL with standard HTTP POST requests. Ratings are computed from review data and mapped to colors for visual feedback.
437
+
**Want to explore the source code or run it locally?** The complete Streamlit frontend code is available at [https://github.com/couchbase-examples/couchbase-data_api-appsync-demo/tree/main/src/frontend](https://github.com/couchbase-examples/couchbase-data_api-appsync-demo/tree/main/src/frontend). The frontend consists of `home.py` (tab-based navigation and connection settings) and `search_hotels.py` (hotel search with map visualization using `pydeck`). It uses the `requests` library to call AppSync GraphQL with standard HTTP POST requests. Ratings are computed from review data and mapped to colors for visual feedback.
To run locally: clone the repo, install dependencies with `pip install -r requirements.txt`, navigate to `src/frontend`, and run `streamlit run home.py`. The app will start at `http://localhost:8501`.
0 commit comments