{"id":10371,"date":"2025-11-05T21:47:42","date_gmt":"2025-11-06T05:47:42","guid":{"rendered":"https:\/\/www.couchbase.com\/developers\/tutorials\/appsync-data-api-streamlit-travel-sample\/"},"modified":"2025-11-05T21:47:42","modified_gmt":"2025-11-06T05:47:42","slug":"appsync-data-api-streamlit-travel-sample","status":"publish","type":"tutorials","link":"https:\/\/www.couchbase.com\/fr\/developers\/tutorials\/appsync-data-api-streamlit-travel-sample\/","title":{"rendered":"Build a Geospatial Hotel Search App with AWS AppSync, Couchbase Data API, and Streamlit"},"content":{"rendered":"\n<h3 id=\"h-tutorial-appsync-couchbase-data-api-streamlit-travel-sample\" class=\"wp-block-heading\">Tutorial: AppSync + Couchbase Data API + Streamlit (Travel Sample)<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\"streamlit-map.jpg\" alt=\"Final result (Streamlit map)\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you want to see the final code you can refer to it here: <a href=\"https:\/\/github.com\/couchbase-examples\/couchbase-data_api-appsync-demo\">Final Demo Code<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">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 \u2014 end to end, with inlined code.<\/p>\n\n\n\n<h4 id=\"h-prerequisites\" class=\"wp-block-heading\">Prerequisites<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><a href=\"https:\/\/cloud.couchbase.com\/sign-up\">Couchbase Capella account<\/a><\/strong> with a <a href=\"https:\/\/docs.couchbase.com\/cloud\/get-started\/create-account.html\">running cluster<\/a><\/li>\n\n\n<li><strong><a href=\"https:\/\/docs.couchbase.com\/cloud\/clusters\/data-service\/import-data-documents.html\">Travel-sample bucket<\/a><\/strong> imported into your cluster<\/li>\n\n\n<li><strong><a href=\"https:\/\/docs.couchbase.com\/cloud\/data-api-guide\/data-api-start.html\">Data API enabled<\/a><\/strong> in Capella (via the cluster&#8217;s Connect page)\n<ul>\n<li><strong>Important:<\/strong> Set Allowed IP address to <strong>&#8220;Allow access from anywhere&#8221;<\/strong> for demo purposes<\/li>\n<li>This configuration is required for this demo to function with AWS AppSync<\/li>\n<li>Not recommended for production\u2014see <a href=\"https:\/\/docs.couchbase.com\/cloud\/data-api-guide\/data-api-start.html\">documentation<\/a> for secure network configurations<\/li>\n<\/ul>\n<\/li>\n\n\n<li><strong><a href=\"https:\/\/aws.amazon.com\/\">AWS account<\/a><\/strong> with permissions to create AppSync APIs<\/li>\n\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 id=\"h-enable-couchbase-data-api\" class=\"wp-block-heading\">Enable Couchbase Data API<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>What is Data API?<\/strong>\nCouchbase 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:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Enables driverless mode:<\/strong> No need to deploy SDKs in FaaS environments (AWS Lambda, Azure Functions)<\/li>\n\n\n<li><strong>Is lightweight:<\/strong> Avoids heavy SDK initialization overhead in stateless functions<\/li>\n\n\n<li><strong>Simplifies integration:<\/strong> Uses standard HTTP\u2014no SDK version management or dependencies<\/li>\n\n\n<li><strong>Is language agnostic:<\/strong> Works with any platform that can make HTTP requests<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Learn more: <a href=\"https:\/\/docs.couchbase.com\/cloud\/data-api-guide\/data-api-sdks.html\">Data API vs. SDKs<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Steps:<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>In Capella, enable Data API for your project\/cluster (single click in the cluster settings).<\/li>\n\n\n<li>Copy the Data API base URL (something like <code>https:\/\/your-cluster.apps.cloud.couchbase.com<\/code>). Keep your Couchbase username\/password handy.<\/li>\n\n\n<li>Ensure the Travel Sample bucket (<code>travel-sample<\/code>) is loaded and accessible.<\/li>\n\n<\/ol>\n\n\n\n<h5 id=\"h-screenshot\" class=\"wp-block-heading\">Screenshot<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\"data-api-endpoint.jpg\" alt=\"Couchbase Data API endpoint\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Notes:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>We will query <code>travel-sample.inventory.hotel<\/code> and <code>travel-sample.inventory.airport<\/code> collections using a geospatial distance calculation.<\/li>\n\n\n<li>Credentials are configured as environment variables in AppSync and used by the resolver to call Data API.<\/li>\n\n\n<li>Data API authenticates each request via Basic auth (username:password Base64-encoded in the <code>Authorization<\/code> header).<\/li>\n\n\n<li>The query uses SQL++ Common Table Expressions (CTEs) to first find the airport, then calculate distances to nearby hotels.<\/li>\n\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 id=\"h-create-aws-appsync-graphql-api\" class=\"wp-block-heading\">Create AWS AppSync GraphQL API<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Why AppSync?<\/strong>\nAppSync 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.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Steps:<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Create an AppSync GraphQL API:\n<ul>\n<li>Choose <strong>&#8220;Build from scratch&#8221;<\/strong> option when prompted<\/li>\n<li>Select <strong>Public API<\/strong> with <strong>API key<\/strong> authentication for demo simplicity<\/li>\n<\/ul>\n<\/li>\n\n<\/ol>\n\n\n\n<h5 id=\"h-define-the-schema-paste-into-the-schema-editor\" class=\"wp-block-heading\">Define the schema (paste into the schema editor)<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">This schema defines:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>Hotel<\/code>: type matching the Travel Sample hotel documents with all fields including geo location and reviews.<\/li>\n\n\n<li><code>Airport<\/code>: type with <code>name<\/code> and nested <code>location<\/code> (GeoObject) representing airport information.<\/li>\n\n\n<li><code>GeoObject<\/code>: shared type for latitude, longitude, and accuracy used by both hotels and airports.<\/li>\n\n\n<li><code>Output<\/code>: response type that returns both <code>hotels<\/code> array and <code>airport<\/code> object.<\/li>\n\n\n<li><code>Query.listHotelsNearAirport<\/code>: the main query that takes an airport name and distance in km, returns hotels within that radius plus the airport information.<\/li>\n\n<\/ul>\n\n\n\n<pre class=\"wp-block-code language-graphql\"><code>type Airport {\n\tlocation: GeoObject\n\tname: String\n}\n\ntype GeoObject {\n\taccuracy: String\n\tlat: Float\n\tlon: Float\n}\n\ntype Hotel {\n\taddress: String\n\talias: String\n\tcheckin: String\n\tcheckout: String\n\tcity: String\n\tcountry: String\n\tdescription: String\n\tdirections: String\n\temail: String\n\tfax: String\n\tfree_breakfast: Boolean\n\tfree_internet: Boolean\n\tfree_parking: Boolean\n\tgeo: GeoObject\n\tid: Float\n\tname: String\n\tpets_ok: Boolean\n\tphone: String\n\tprice: String\n\tpublic_likes: [String]\n\treviews: [HotelReviewObject]\n\tstate: String\n\ttitle: String\n\ttollfree: String\n\ttype: String\n\turl: String\n\tvacancy: Boolean\n}\n\ntype HotelRatingObject {\n\tCleanliness: Float\n\tLocation: Float\n\tOverall: Float\n\tRooms: Float\n\tService: Float\n\tValue: Float\n}\n\ntype HotelReviewObject {\n\tauthor: String\n\tcontent: String\n\tdate: String\n\tratings: HotelRatingObject\n}\n\ntype Output {\n\thotels: [Hotel]\n\tairport: Airport\n}\n\ntype Query {\n\tlistHotelsNearAirport(airportName: String!, withinKm: Int!): Output\n}\n\nschema {\n\tquery: Query\n}\n<\/code><\/pre>\n\n\n\n<h5 id=\"h-screenshot\" class=\"wp-block-heading\">Screenshot<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\"appsync-schema.jpg\" alt=\"AppSync schema\"><\/p>\n\n\n\n<h5 id=\"h-create-http-data-source\" class=\"wp-block-heading\">Create HTTP data source<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>What&#8217;s an HTTP data source?<\/strong>\nAppSync can call external HTTP APIs. You configure a base URL (your Data API endpoint), and resolvers send requests to it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Steps:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>In AppSync, create a new HTTP data source.<\/li>\n\n\n<li>Set the endpoint to your Couchbase Data API base URL (from step 1).<\/li>\n\n\n<li><strong>Important:<\/strong> Do NOT enable &#8220;Authorization configuration&#8221;, since credentials will be passed dynamically via the resolver using AppSync environment variables.<\/li>\n\n<\/ul>\n\n\n\n<h5 id=\"h-screenshot\" class=\"wp-block-heading\">Screenshot<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\"appsync-data-source.jpg\" alt=\"AppSync Data Source\"><\/p>\n\n\n\n<h5 id=\"h-configure-environment-variables-in-appsync\" class=\"wp-block-heading\">Configure environment variables in AppSync<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Why environment variables?<\/strong>\nStoring credentials as environment variables in AppSync keeps them centralized. This approach:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Avoids exposing credentials to clients<\/li>\n\n\n<li>Makes credential rotation easier (update once in AppSync, not in every client)<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Steps:<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>In the AppSync console, navigate to your API \u2192 <strong>Settings<\/strong> \u2192 <strong>Environment variables<\/strong>.<\/li>\n\n\n<li>Add the following environment variables:\n<ul>\n<li><strong>Key<\/strong>: <code>cb_username<\/code>, <strong>Value<\/strong>: Your Couchbase username<\/li>\n<li><strong>Key<\/strong>: <code>cb_password<\/code>, <strong>Value<\/strong>: Your Couchbase password<\/li>\n<\/ul>\n<\/li>\n\n\n<li>Save the changes.<\/li>\n\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">These environment variables will be accessible in your resolvers via <code>ctx.env.cb_username<\/code> and <code>ctx.env.cb_password<\/code>.<\/p>\n\n\n\n<h5 id=\"h-screenshot\" class=\"wp-block-heading\">Screenshot<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\"appsync-env-vars.jpg\" alt=\"AppSync Environment Variables\"><\/p>\n\n\n\n<h5 id=\"h-add-a-javascript-unit-resolver-for-codequery-listhotelsnearairportcode\" class=\"wp-block-heading\">Add a JavaScript Unit Resolver for <code>Query.listHotelsNearAirport<\/code><\/h5>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>What does this resolver do?<\/strong>\nAppSync resolvers have two functions:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><code>request()<\/code> \u2014 transforms the GraphQL request into an HTTP request to send to the data source.<\/li>\n\n\n<li><code>response()<\/code> \u2014 transforms the HTTP response from the data source back into GraphQL data.<\/li>\n\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Our resolver:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Reads <code>cb_username<\/code> and <code>cb_password<\/code> from AppSync environment variables (<code>ctx.env<\/code>).<\/li>\n\n\n<li>Extracts <code>airportName<\/code> and <code>withinKm<\/code> from the GraphQL arguments.<\/li>\n\n\n<li>Constructs a geospatial SQL++ query to find hotels near the specified airport.<\/li>\n\n\n<li>Builds a Data API Query Service request:\n<ul>\n<li><strong>Endpoint<\/strong>: <code>\/_p\/query\/query\/service<\/code> (Data API&#8217;s SQL++ query endpoint).<\/li>\n<li><strong>Headers<\/strong>: <code>Authorization: Basic &lt;base64(username:password)&gt;<\/code>, <code>Content-Type: application\/json<\/code>.<\/li>\n<li><strong>Body<\/strong>: <code>{ query_context: \"default:travel-sample.inventory\", statement: \"...\", args: [airportName, withinKm], timeout: \"30m\" }<\/code>.<\/li>\n<\/ul>\n<\/li>\n\n\n<li>Returns both hotels and airport information in the <code>Output<\/code> schema format.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Why <code>query_context<\/code>?<\/strong>\nSetting <code>query_context<\/code> to <code>default:travel-sample.inventory<\/code> lets you write <code>FROM hotel<\/code> instead of the fully qualified <code>FROM travel-sample.inventory.hotel<\/code> in your SQL++. It&#8217;s a namespace shortcut.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Why environment variables for credentials?<\/strong>\nStoring credentials as environment variables in AppSync means:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Credentials never leave the server or get exposed to clients.<\/li>\n\n\n<li>Easy credential rotation without updating client code.<\/li>\n\n\n<li>Centralized credential management across all resolvers.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Paste this code:<\/p>\n\n\n\n<pre class=\"wp-block-code language-javascript\"><code>import { util } from &#039;@aws-appsync\/utils&#039;;\n\nexport function request(ctx) {\n    \/\/ Read credentials from AppSync environment variables\n    const username = ctx.env.cb_username;\n    const password = ctx.env.cb_password;\n    \n    \/\/ Define the Couchbase keyspace (bucket.scope.collection)\n    const bucket = &quot;travel-sample&quot;;\n    const scope = &quot;inventory&quot;;\n\n    \/\/ Build Basic auth header for Data API\n    \/\/ Data API expects: Authorization: Basic &lt;base64(username:password)&gt;\n    const token = util.base64Encode(`${username}:${password}`);\n    const auth = `Basic ${token}`;\n\n    \/\/ Construct a geospatial SQL++ query using a Common Table Expression (CTE)\n    \/\/ The query:\n    \/\/ 1. WITH clause: Finds the airport by name and extracts its coordinates\n    \/\/ 2. Main SELECT: Joins hotels with airport location and calculates distance\n    \/\/ 3. WHERE clause: Filters hotels within the specified radius using Pythagorean theorem\n    \/\/ Using $1, $2 as positional parameters for security (prevents SQL injection)\n    const sql_query = `\n      WITH airport_loc AS (\n        SELECT a.geo.lat AS alat, \n               a.geo.lon AS alon, \n               IFMISSINGORNULL(a.geo.accuracy, &quot;APPROXIMATE&quot;) AS accuracy\n        FROM airport AS a\n        WHERE a.airportname = $1\n        LIMIT 1\n      )\n      SELECT h.*, airport_loc.alat, airport_loc.alon, airport_loc.accuracy\n      FROM hotel AS h, airport_loc\n      WHERE airport_loc.alat IS NOT MISSING\n        AND POWER(h.geo.lat - airport_loc.alat, 2)\n          + POWER(h.geo.lon - airport_loc.alon, 2) &lt;= POWER($2 \/ 111, 2)\n    `;\n\n    \/\/ Log to CloudWatch for debugging (best practice)\n    console.log(&quot;Request Context:&quot;, ctx);\n    \n    \/\/ Build the HTTP request object for the Data API Query Service\n    const requestObject = {\n        method: &#039;POST&#039;,\n        resourcePath: &#039;\/_p\/query\/query\/service&#039;,  \/\/ Data API SQL++ endpoint - see https:\/\/docs.couchbase.com\/cloud\/data-api-reference\/index.html#tag\/Query\n        params: {\n            headers: {\n                &#039;Accept&#039;: &#039;application\/json&#039;,\n                &#039;Content-Type&#039;: &#039;application\/json&#039;,\n                &#039;Authorization&#039;: auth  \/\/ Basic auth using environment variables\n            },\n            body: {\n                query_context: `default:${bucket}.${scope}`,  \/\/ Namespace shortcut\n                statement: sql_query,  \/\/ The geospatial SQL++ query\n                args: [ctx.arguments.airportName, ctx.arguments.withinKm],  \/\/ Positional parameters\n                timeout: &#039;30m&#039;  \/\/ Query timeout\n            }\n        }\n    };\n    \n    \/\/ Log the outgoing request\n    console.log(&quot;Outgoing Request to Data API:&quot;, requestObject);\n    \n    return requestObject;\n}\n\nexport function response(ctx) {\n    \/\/ Log the complete response context\n    console.log(&quot;Response Context:&quot;, ctx);\n    \n    \/\/ Data API returns JSON like: { results: [ {...hotel1...}, {...hotel2...} ], ... }\n    \/\/ Each result contains hotel fields plus airport coordinates (alat, alon, accuracy)\n    let parsedResult = ctx.result.body;\n    if (typeof ctx.result.body === &#039;string&#039;) {\n        parsedResult = JSON.parse(ctx.result.body);\n        console.log(&quot;Parsed Result:&quot;, parsedResult);\n    }\n    \n    const results = parsedResult.results || [];\n    \n    \/\/ Extract airport information from the first result (all results have the same airport location)\n    let airport = null;\n    if (results.length &gt; 0) {\n        const first = results[0];\n        airport = {\n            name: ctx.arguments.airportName,  \/\/ Use the input airport name\n            location: {\n                lat: first.alat,\n                lon: first.alon,\n                accuracy: first.accuracy\n            }\n        };\n    }\n    \n    \/\/ Clean up hotels by removing airport location fields (alat, alon, accuracy)\n    \/\/ These were added by the JOIN but aren&#039;t part of the Hotel schema\n    const hotels = results.map(hotel =&gt; {\n        const { alat, alon, accuracy, ...cleanHotel } = hotel;\n        return cleanHotel;\n    });\n    \n    \/\/ Return in the Output schema format with both hotels and airport\n    return {\n        hotels: hotels,\n        airport: airport\n    };\n}\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Key takeaways:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>ctx.env<\/code> provides access to AppSync environment variables (credentials stored securely).<\/li>\n\n\n<li><code>ctx.arguments<\/code> gives you the GraphQL args: <code>airportName<\/code> and <code>withinKm<\/code>.<\/li>\n\n\n<li><code>util.base64Encode<\/code> is an AppSync helper to encode credentials.<\/li>\n\n\n<li><code>resourcePath<\/code> is the API endpoint path relative to your HTTP data source base URL. In this case, <code>\/_p\/query\/query\/service<\/code> is the <a href=\"https:\/\/docs.couchbase.com\/cloud\/data-api-reference\/index.html#tag\/Query\">Data API Query Service endpoint<\/a> for executing SQL++ queries.<\/li>\n\n\n<li><code>query_context<\/code> sets the default bucket\/scope for SQL++, allowing short names like <code>hotel<\/code> instead of <code>travel-sample.inventory.hotel<\/code>.<\/li>\n\n\n<li>Using positional parameters (<code>$1<\/code>, <code>$2<\/code>) in the SQL++ query prevents SQL injection.<\/li>\n\n\n<li>Distance calculation uses Pythagorean theorem approximation.<\/li>\n\n\n<li>The response function constructs an <code>Airport<\/code> object from the result data and input arguments.<\/li>\n\n\n<li>Hotel objects are cleaned to remove the joined airport coordinate fields before returning.<\/li>\n\n\n<li>CloudWatch logging helps debug the complex geospatial query and response transformation.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Save and deploy your resolver.<\/p>\n\n\n\n<h5 id=\"h-screenshot\" class=\"wp-block-heading\">Screenshot<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\"appsync-resolver.jpg\" alt=\"AppSync Resolver\"><\/p>\n\n\n\n<h5 id=\"h-enable-appsync-requestresponse-logging-recommended\" class=\"wp-block-heading\">Enable AppSync request\/response logging (recommended)<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Why enable logging?<\/strong>\nCloudWatch logs let you see exactly what your resolver sends to Data API and what it receives back. This is invaluable for debugging:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Incorrect SQL++ syntax? Check the <code>statement<\/code> in the request log.<\/li>\n\n\n<li>Auth errors? Check the <code>Authorization<\/code> header and Data API response.<\/li>\n\n\n<li>Unexpected results? Compare the Data API JSON with what AppSync returns to the client.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Steps:<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>In the AppSync console, open your API \u2192 <strong>Settings<\/strong> \u2192 <strong>Logging<\/strong>.<\/li>\n\n\n<li>Choose (or create) a CloudWatch Log Group.<\/li>\n\n\n<li>Set <strong>Field resolver log level<\/strong> to at least <strong>ERROR<\/strong> (use <strong>INFO<\/strong> or <strong>ALL<\/strong> during development for full request\/response logs).<\/li>\n\n\n<li>Save.<\/li>\n\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Now, every resolver invocation will log to CloudWatch. You can view logs in the CloudWatch console under the log group you selected.<\/p>\n\n\n\n<h5 id=\"h-screenshot\" class=\"wp-block-heading\">Screenshot<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\"appsync-logging-seeting.jpg\" alt=\"AppSync Logging Settings\"><\/p>\n\n\n\n<h5 id=\"h-quick-test-optional\" class=\"wp-block-heading\">Quick test (optional)<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">Test your resolver directly in the AppSync console before building the frontend.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>In the AppSync console, open <strong>Queries<\/strong>.<\/li>\n\n\n<li>Paste this query, replacing the airport name and distance as needed:<\/li>\n\n<\/ol>\n\n\n\n<pre class=\"wp-block-code language-graphql\"><code>query ListHotelsNearAirport {\n  listHotelsNearAirport(\n    airportName: &quot;Les Loges&quot;\n    withinKm: 50\n  ) {\n    hotels {\n      id\n      name\n      address\n      city\n      country\n      phone\n      price\n      url\n      geo { lat lon }\n      reviews { ratings { Overall } }\n    }\n    airport {\n      name\n      location {\n        lat\n        lon\n        accuracy\n      }\n    }\n  }\n}\n<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Click <strong>Run<\/strong>. You should see a JSON response with:\n<ul>\n<li>An array of hotels within 50km of Les Loges airport<\/li>\n<li>Airport information including name and location coordinates<\/li>\n<\/ul>\n<\/li>\n\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Try different airport names like <strong>&#8220;San Francisco Intl&#8221;<\/strong>, <strong>&#8220;Charles de Gaulle&#8221;<\/strong>, <strong>&#8220;Luton&#8221;<\/strong>, or <strong>&#8220;London St Pancras&#8221;<\/strong> to see results from different locations.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Troubleshooting:<\/strong> If you encounter a &#8220;connection timed out&#8221; error, verify that your Data API has IP address access set to <strong>&#8220;Allow access from anywhere&#8221;<\/strong> in the Capella Connect page (see Prerequisites section). This is required for AWS AppSync to reach your cluster.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If it works, you&#8217;ve successfully bridged AppSync \u2192 Data API \u2192 Couchbase with geospatial querying!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Note:<\/strong> The credentials are read from the environment variables you configured earlier, so you don&#8217;t need to pass them in the query.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 id=\"h-test-your-appsync-api-with-the-hosted-streamlit-frontend\" class=\"wp-block-heading\">Test Your AppSync API with the Hosted Streamlit Frontend<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Now that you&#8217;ve set up your AWS AppSync backend with the Couchbase Data API integration, you can test it immediately using our hosted Streamlit frontend\u2014no need to install or run anything locally!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Visit the live Streamlit app at <strong><a href=\"https:\/\/couchbase-data-api-appsync-demo.streamlit.app\/\">https:\/\/couchbase-data-api-appsync-demo.streamlit.app\/<\/a><\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The app provides an interactive map-based interface where you can search for hotels near airports. Simply enter your <strong>AppSync GraphQL Endpoint<\/strong> and <strong>AppSync API Key<\/strong> in the sidebar (note that Couchbase credentials are securely stored as environment variables in AppSync, so you don&#8217;t need to enter them). Click the <strong>&#8220;Search Hotels&#8221;<\/strong> tab, enter an airport name like <strong>&#8220;San Francisco Intl&#8221;<\/strong>, <strong>&#8220;Les Loges&#8221;<\/strong>, <strong>&#8220;Luton&#8221;<\/strong>, or <strong>&#8220;London St Pancras&#8221;<\/strong> and a distance like <strong>100 km<\/strong>, then click &#8220;Search&#8221;. A loading spinner will appear while fetching results.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">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 &#8220;Raw response&#8221; section to see the full JSON data from AppSync.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\"streamlit-search.jpg\" alt=\"Streamlit search interface\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\"streamlit-map.jpg\" alt=\"Streamlit map with hotels and airport\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Want to explore the source code or run it locally?<\/strong> The complete Streamlit frontend code is available at <a href=\"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<\/a>. The frontend consists of <code>home.py<\/code> (tab-based navigation and connection settings) and <code>search_hotels.py<\/code> (hotel search with map visualization using <code>pydeck<\/code>). It uses the <code>requests<\/code> library to call AppSync GraphQL with standard HTTP POST requests. Ratings are computed from review data and mapped to colors for visual feedback.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To run locally:<\/p>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code># Clone the repository\ngit clone https:\/\/github.com\/couchbase-examples\/couchbase-data_api-appsync-demo.git\n\n# Navigate to the project directory\ncd couchbase-data_api-appsync-demo\n\n# Create a virtual environment\npython3 -m venv .venv\n\n# Activate the virtual environment\nsource .\/.venv\/bin\/activate\n\n# Install required dependencies\npip install -r requirements.txt\n\n# Run the Streamlit app\nstreamlit run src\/frontend\/home.py\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The app will start at <code>http:\/\/localhost:8501<\/code>.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 id=\"h-why-this-architecture\" class=\"wp-block-heading\">Why This Architecture?<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">You might wonder why we chose this particular stack instead of calling Couchbase Data API directly from the frontend. Here&#8217;s the reasoning behind each technology choice:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>AppSync as an API Gateway<\/strong> provides credential security by storing your Couchbase credentials as environment variables on the server side\u2014your frontend never sees or handles database credentials. It also acts as a unified gateway that can aggregate data from multiple sources as your application grows. You get built-in authentication, authorization, request throttling, caching, and CloudWatch logging without building these features yourself.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>GraphQL over REST<\/strong> gives clients the flexibility to request exactly the data they need, reducing bandwidth and improving performance. Instead of multiple REST endpoints, you have one endpoint with a strongly-typed schema that serves as self-documenting API documentation. The schema can evolve over time by adding new fields without breaking existing queries.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Streamlit for the frontend<\/strong> enables rapid development with pure Python\u2014no HTML, CSS, or JavaScript required. It&#8217;s perfect for prototypes and internal tools, with built-in support for maps (via pydeck), charts, and tables. You get direct access to data science libraries like pandas and easy integration with any HTTP API. Plus, Streamlit apps can be deployed to Streamlit Cloud in minutes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>The architecture summary:<\/strong> Frontend (Streamlit) \u2192 API Layer (AppSync GraphQL) \u2192 Data API (Couchbase) \u2192 Database (Capella). This separates concerns so each layer can be developed, tested, and scaled independently.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 id=\"h-conclusion\" class=\"wp-block-heading\">Conclusion<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">You&#8217;ve successfully built a complete demo showcasing <strong>Couchbase Data API<\/strong> integration with <strong>AWS AppSync GraphQL<\/strong> and <strong>Streamlit<\/strong>\u2014creating a serverless geospatial hotel search application that executes SQL++ queries through AppSync resolvers, manages credentials securely via environment variables, and visualizes results on interactive maps with color-coded ratings and dual layers for hotels and airports.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Tutorial: AppSync + Couchbase Data API + Streamlit (Travel Sample) If you want to see the final code you can refer to it here: Final Demo Code 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 [&hellip;]<\/p>\n","protected":false},"author":0,"featured_media":0,"menu_order":0,"template":"","meta":{"_acf_changed":false,"inline_featured_image":false,"_acf":"","footnotes":""},"tutorial-languages":[653,606],"tutorial-tags":[660,665,642],"tutorial-technologies":[548,549],"tutorial-types":[555],"class_list":["post-10371","tutorials","type-tutorials","status-publish","hentry","tutorial-languages-nodejs","tutorial-languages-python","tutorial-tags-data-api","tutorial-tags-graphql","tutorial-tags-streamlit","tutorial-technologies-kv","tutorial-technologies-query","tutorial-types-tutorial"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v28.8 (Yoast SEO v28.9) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Build a Geospatial Hotel Search App with AWS AppSync, Couchbase Data API, and Streamlit - Couchbase<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.couchbase.com\/fr\/developers\/tutorials\/appsync-data-api-streamlit-travel-sample\/\" \/>\n<meta property=\"og:locale\" content=\"fr_FR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Build a Geospatial Hotel Search App with AWS AppSync, Couchbase Data API, and Streamlit\" \/>\n<meta property=\"og:description\" content=\"Tutorial: AppSync + Couchbase Data API + Streamlit (Travel Sample) If you want to see the final code you can refer to it here: Final Demo Code 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 [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.couchbase.com\/fr\/developers\/tutorials\/appsync-data-api-streamlit-travel-sample\/\" \/>\n<meta property=\"og:site_name\" content=\"Couchbase\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/Couchbase\/\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.couchbase.com\/wp-content\/uploads\/2026\/10\/Cloud-2.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2548\" \/>\n\t<meta property=\"og:image:height\" content=\"1171\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:site\" content=\"@couchbase\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"13 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/fr\\\/developers\\\/tutorials\\\/appsync-data-api-streamlit-travel-sample\\\/\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/fr\\\/developers\\\/tutorials\\\/appsync-data-api-streamlit-travel-sample\\\/\",\"name\":\"Build a Geospatial Hotel Search App with AWS AppSync, Couchbase Data API, and Streamlit - Couchbase\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/fr\\\/#website\"},\"datePublished\":\"2025-11-06T05:47:42+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/fr\\\/developers\\\/tutorials\\\/appsync-data-api-streamlit-travel-sample\\\/#breadcrumb\"},\"inLanguage\":\"fr-FR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.couchbase.com\\\/fr\\\/developers\\\/tutorials\\\/appsync-data-api-streamlit-travel-sample\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/fr\\\/developers\\\/tutorials\\\/appsync-data-api-streamlit-travel-sample\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.couchbase.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Build a Geospatial Hotel Search App with AWS AppSync, Couchbase Data API, and Streamlit\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/fr\\\/#website\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/fr\\\/\",\"name\":\"Couchbase\",\"description\":\"The Operational Data Platform for AI\u2122\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/fr\\\/#organization\"},\"alternateName\":\"Couchbase, Inc.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.couchbase.com\\\/fr\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"fr-FR\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/fr\\\/#organization\",\"name\":\"Couchbase\",\"alternateName\":\"Couchbase, Inc.\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/fr\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"fr-FR\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/fr\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/Couchbase_Logo_Couchbase_Token_Red-1.png\",\"contentUrl\":\"https:\\\/\\\/www.couchbase.com\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/Couchbase_Logo_Couchbase_Token_Red-1.png\",\"width\":1129,\"height\":1129,\"caption\":\"Couchbase\"},\"image\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/fr\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/Couchbase\\\/\",\"https:\\\/\\\/x.com\\\/couchbase\",\"https:\\\/\\\/www.youtube.com\\\/c\\\/CouchbaseServer\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/couchbase\\\/\",\"https:\\\/\\\/github.com\\\/couchbase\\\/\",\"https:\\\/\\\/en.wikipedia.org\\\/wiki\\\/Couchbase,_Inc.\"],\"description\":\"Couchbase is a database software company headquartered in San Jose, California, providing an operational data platform for AI used by hundreds of global enterprises.\",\"legalName\":\"Couchbase, Inc.\",\"foundingDate\":\"2011-01-01\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Build a Geospatial Hotel Search App with AWS AppSync, Couchbase Data API, and Streamlit - Couchbase","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.couchbase.com\/fr\/developers\/tutorials\/appsync-data-api-streamlit-travel-sample\/","og_locale":"fr_FR","og_type":"article","og_title":"Build a Geospatial Hotel Search App with AWS AppSync, Couchbase Data API, and Streamlit","og_description":"Tutorial: AppSync + Couchbase Data API + Streamlit (Travel Sample) If you want to see the final code you can refer to it here: Final Demo Code 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 [&hellip;]","og_url":"https:\/\/www.couchbase.com\/fr\/developers\/tutorials\/appsync-data-api-streamlit-travel-sample\/","og_site_name":"Couchbase","article_publisher":"https:\/\/www.facebook.com\/Couchbase\/","og_image":[{"width":2548,"height":1171,"url":"https:\/\/www.couchbase.com\/wp-content\/uploads\/2026\/10\/Cloud-2.png","type":"image\/png"}],"twitter_card":"summary_large_image","twitter_site":"@couchbase","twitter_misc":{"Est. reading time":"13 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.couchbase.com\/fr\/developers\/tutorials\/appsync-data-api-streamlit-travel-sample\/","url":"https:\/\/www.couchbase.com\/fr\/developers\/tutorials\/appsync-data-api-streamlit-travel-sample\/","name":"Build a Geospatial Hotel Search App with AWS AppSync, Couchbase Data API, and Streamlit - Couchbase","isPartOf":{"@id":"https:\/\/www.couchbase.com\/fr\/#website"},"datePublished":"2025-11-06T05:47:42+00:00","breadcrumb":{"@id":"https:\/\/www.couchbase.com\/fr\/developers\/tutorials\/appsync-data-api-streamlit-travel-sample\/#breadcrumb"},"inLanguage":"fr-FR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.couchbase.com\/fr\/developers\/tutorials\/appsync-data-api-streamlit-travel-sample\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.couchbase.com\/fr\/developers\/tutorials\/appsync-data-api-streamlit-travel-sample\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.couchbase.com\/"},{"@type":"ListItem","position":2,"name":"Build a Geospatial Hotel Search App with AWS AppSync, Couchbase Data API, and Streamlit"}]},{"@type":"WebSite","@id":"https:\/\/www.couchbase.com\/fr\/#website","url":"https:\/\/www.couchbase.com\/fr\/","name":"Couchbase","description":"The Operational Data Platform for AI\u2122","publisher":{"@id":"https:\/\/www.couchbase.com\/fr\/#organization"},"alternateName":"Couchbase, Inc.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.couchbase.com\/fr\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"fr-FR"},{"@type":"Organization","@id":"https:\/\/www.couchbase.com\/fr\/#organization","name":"Couchbase","alternateName":"Couchbase, Inc.","url":"https:\/\/www.couchbase.com\/fr\/","logo":{"@type":"ImageObject","inLanguage":"fr-FR","@id":"https:\/\/www.couchbase.com\/fr\/#\/schema\/logo\/image\/","url":"https:\/\/www.couchbase.com\/wp-content\/uploads\/2026\/11\/Couchbase_Logo_Couchbase_Token_Red-1.png","contentUrl":"https:\/\/www.couchbase.com\/wp-content\/uploads\/2026\/11\/Couchbase_Logo_Couchbase_Token_Red-1.png","width":1129,"height":1129,"caption":"Couchbase"},"image":{"@id":"https:\/\/www.couchbase.com\/fr\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/Couchbase\/","https:\/\/x.com\/couchbase","https:\/\/www.youtube.com\/c\/CouchbaseServer","https:\/\/www.linkedin.com\/company\/couchbase\/","https:\/\/github.com\/couchbase\/","https:\/\/en.wikipedia.org\/wiki\/Couchbase,_Inc."],"description":"Couchbase est une soci\u00e9t\u00e9 de logiciels de bases de donn\u00e9es dont le si\u00e8ge social est situ\u00e9 \u00e0 San Jose, en Californie, et qui fournit une plateforme op\u00e9rationnelle de donn\u00e9es pour l\u2019IA utilis\u00e9e par des centaines d\u2019entreprises mondiales.","legalName":"Couchbase, Inc.","foundingDate":"2011-01-01"}]}},"acf":[],"permalink_manager":null,"_links":{"self":[{"href":"https:\/\/www.couchbase.com\/fr\/wp-json\/wp\/v2\/tutorials\/10371","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.couchbase.com\/fr\/wp-json\/wp\/v2\/tutorials"}],"about":[{"href":"https:\/\/www.couchbase.com\/fr\/wp-json\/wp\/v2\/types\/tutorials"}],"version-history":[{"count":0,"href":"https:\/\/www.couchbase.com\/fr\/wp-json\/wp\/v2\/tutorials\/10371\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.couchbase.com\/fr\/wp-json\/wp\/v2\/media?parent=10371"}],"wp:term":[{"taxonomy":"tutorial-languages","embeddable":true,"href":"https:\/\/www.couchbase.com\/fr\/wp-json\/wp\/v2\/tutorial-languages?post=10371"},{"taxonomy":"tutorial-tags","embeddable":true,"href":"https:\/\/www.couchbase.com\/fr\/wp-json\/wp\/v2\/tutorial-tags?post=10371"},{"taxonomy":"tutorial-technologies","embeddable":true,"href":"https:\/\/www.couchbase.com\/fr\/wp-json\/wp\/v2\/tutorial-technologies?post=10371"},{"taxonomy":"tutorial-types","embeddable":true,"href":"https:\/\/www.couchbase.com\/fr\/wp-json\/wp\/v2\/tutorial-types?post=10371"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}