Skip to content

Minor semantic changes #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,24 @@ This tutorial demonstrates how to work with Couchbase's Data API to manage airpo

This provides a comprehensive Airport Information System that manages airport data and provides related travel information from the Couchbase travel-sample dataset.

## Platform Tutorials

Choose your preferred serverless platform to get started:

- **AWS Lambda**: [View Tutorial](./aws-lambdas/README.md)
- **Cloudflare Workers**: [View Tutorial](./cloudflare-workers/README.md)

### Coming Soon
- **Azure Functions**
- **Google Cloud Functions**

### Architecture Diagrams

#### Cloudflare Workers
![Cloudflare Workers Architecture](./assets/cloudflare-workers.png)

#### AWS Lambda
*Architecture diagram will be added*
![AWS Lambda Architecture](./assets/aws-lambdas.png)

### Core Features

Expand Down
Binary file added assets/aws-lambdas.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
171 changes: 63 additions & 108 deletions aws-lambdas/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,18 @@

This project demonstrates how to build a serverless API using **AWS Lambda and API Gateway** that interfaces with Couchbase's Data API to manage airport data from the travel-sample dataset.

## Overview

The API provides a comprehensive Airport Information System that manages airport data and provides related travel information from the Couchbase travel-sample dataset:

### Airport Management (CRUD Operations)
- `GET /airports/{airportId}` - Retrieve an airport document
- `POST /airports/{airportId}` - Create a new airport document
- `PUT /airports/{airportId}` - Update an existing airport document
- `DELETE /airports/{airportId}` - Delete an airport document

### Airport Information Queries
- `GET /airports/{airportCode}/routes` - Find routes for a specific airport
- `GET /airports/{airportCode}/airlines` - Find airlines that service a specific airport
- `GET /airports/{airportId}/hotels/nearby/{distance}` - Find hotels near a specific airport using geo-spatial FTS
Note: The FTS features require:
1. A Full Text Search index with geo-spatial mapping on hotel documents
2. The travel-sample dataset with hotel documents in the inventory.hotel collection
3. Hotels must have geo coordinates (`geo.lat` and `geo.lon` fields) for proximity search

## Prerequisites

- [Node.js](https://nodejs.org/) (v22.x or later)
- [AWS CLI](https://aws.amazon.com/cli/) configured with appropriate credentials
- AWS IAM Role with Lambda and API Gateway permissions
- Couchbase Server with Data API enabled
- Couchbase travel-sample bucket loaded
- [AWS IAM Role](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles.html) with Lambda and API Gateway permissions
- [Couchbase Capella](https://www.couchbase.com/products/capella/) cluster with Data API enabled
- Couchbase [travel-sample bucket](https://docs.couchbase.com/dotnet-sdk/current/ref/travel-app-data-model.html) loaded

## Setup

Expand Down Expand Up @@ -60,41 +50,9 @@ The API provides a comprehensive Airport Information System that manages airport

## FTS Index Setup

Before using the hotel search functionality, you need to create a Full Text Search index:

```bash
npm run create-fts-index
```

This creates a geo-spatial FTS index called `hotel-geo-index` that enables proximity searches for hotels near airports. The index will be built in the background and will be ready for use shortly after creation.

## Deployment
Before using the hotel search functionality, you need to create a Full Text Search index. Use the Node.js script provided in the root of the repository.

### Deploy Lambda Functions

Run the deployment script:
```bash
npm run deploy-airport-lambdas
```

This script will:
1. Create zip files for each Lambda function
2. Deploy the functions to AWS Lambda
3. Configure environment variables and runtime settings

### Deploy API Gateway

Run the API Gateway deployment script:
```bash
npm run deploy-airport-api
```

This script will:
1. Create a new HTTP API Gateway
2. Set up Lambda integrations
3. Configure routes and CORS settings
4. Create a default stage
5. Output the API endpoint URL
See [../scripts/README.md](../scripts/README.md) for detailed instructions on creating the required `hotel-geo-index` for geo-spatial hotel searches.

## Testing

Expand All @@ -119,75 +77,72 @@ This will:
- Verify response formats and status codes
- Test error handling and edge cases

## API Examples
## Deployment

### Get an airport
```bash
curl https://your-api-gateway-url/airports/airport_1254
```
### Authentication

### Create an airport
```bash
curl -X POST https://your-api-gateway-url/airports/airport_new \
-H "Content-Type: application/json" \
-d '{
"airportname": "Test Airport",
"city": "Test City",
"country": "Test Country",
"faa": "TST",
"geo": {
"alt": 100,
"lat": 34.0522,
"lon": -118.2437
},
"icao": "KTST",
"id": 9999,
"type": "airport",
"tz": "America/Los_Angeles"
}'
```
Before deploying, ensure your AWS CLI is properly authenticated.

### Update an airport
```bash
curl -X PUT https://your-api-gateway-url/airports/airport_1254 \
-H "Content-Type: application/json" \
-d '{
"airportname": "Updated Airport",
"city": "Updated City",
"country": "Updated Country",
"faa": "UPD",
"geo": {
"alt": 200,
"lat": 35.0522,
"lon": -119.2437
},
"icao": "KUPD",
"id": 1254,
"type": "airport",
"tz": "America/Los_Angeles"
}'
```
**Note:** This guide uses **IAM user long-term credentials** with `aws configure` as it's the easiest method to get started. However, [AWS does not recommend this approach](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-authentication.html) for production environments due to security considerations. For production deployments, consider using [IAM Identity Center short-term credentials](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-sso.html) or other more secure authentication methods.

### Delete an airport
#### Setup with AWS Configure
```bash
curl -X DELETE https://your-api-gateway-url/airports/airport_1254
aws configure
```
This will prompt you for:
- AWS Access Key ID
- AWS Secret Access Key
- Default region name
- Default output format (json recommended)

### Find routes for an airport
```bash
curl -X GET "https://your-api-gateway-url/airports/LAX/routes"
```
For detailed instructions on creating IAM users and access keys, see the [AWS documentation](https://docs.aws.amazon.com/cli/latest/userguide/cli-authentication-user.html).

### Deploy Lambda Functions

### Find airlines for an airport
Run the deployment script:
```bash
curl -X GET "https://your-api-gateway-url/airports/LAX/airlines"
npm run deploy-airport-lambdas
```

### Find hotels near an airport
This script will:
1. Create zip files for each Lambda function
2. Deploy the functions to AWS Lambda
3. Configure environment variables and runtime settings

### Deploy API Gateway

Run the API Gateway deployment script:
```bash
curl -X GET "https://your-api-gateway-url/airports/airport_1254/hotels/nearby/10km"
npm run deploy-airport-api
```

## License
This script will:
1. Create a new HTTP API Gateway
2. Set up Lambda integrations
3. Configure routes and CORS settings
4. Create a default stage
5. Output the API endpoint URL

## Project Structure

Here's the structure of the aws-lambdas directory containing Lambda functions, deployment scripts, and tests:

Apache 2.0
```
aws-lambdas/
├── package.json # Dependencies and command definitions
├── README.md
├── scripts/ # Deployment automation
│ ├── deploy_airport_lambda_functions.mjs
│ └── deploy_api_gateway_with_integrations.mjs
├── src/ # Lambda function handlers
│ ├── createAirport.mjs
│ ├── deleteAirport.mjs
│ ├── getAirport.mjs
│ ├── getAirportAirlines.mjs
│ ├── getAirportRoutes.mjs
│ ├── getHotelsNearAirport.mjs
│ └── updateAirport.mjs
└── tests/ # Test suites
├── integration.test.mjs
└── unit.test.mjs
```
3 changes: 1 addition & 2 deletions aws-lambdas/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
"deploy-airport-lambdas": "env-cmd -f .env node scripts/deploy_airport_lambda_functions.mjs",
"deploy-airport-api": "env-cmd -f .env node scripts/deploy_api_gateway_with_integrations.mjs",
"test-unit": "env-cmd -f .env node tests/unit.test.mjs",
"test-integration": "env-cmd -f .env node tests/integration.test.mjs",
"create-fts-index": "env-cmd -f .env ./scripts/create-fts-index.sh"
"test-integration": "env-cmd -f .env node tests/integration.test.mjs"
},
"author": "Viraj Agarwal",
"description": "AWS Lambdas for the Couchbase Data API Serverless Cookbook",
Expand Down
142 changes: 0 additions & 142 deletions aws-lambdas/scripts/create-fts-index.sh

This file was deleted.