A RESTful CRUD API built with the Serverless Framework, AWS Lambda, and Amazon DynamoDB using single table design.
API Gateway → Lambda Functions → DynamoDB (Single Table)
The table uses a composite primary key with prefixed values:
| Key | Format | Example |
|---|---|---|
pk (Partition Key) |
category#<category> |
category#electronics |
sk (Sort Key) |
item#id#<uuid> |
item#id#a1b2c3d4-5678-90ab-cdef-1234567890ab |
| Method | Endpoint | Description |
|---|---|---|
POST |
/items |
Create a new item |
GET |
/items/{category} |
List all items in a category |
GET |
/items/{category}/{id} |
Get a specific item |
PUT |
/items/{category}/{id} |
Update an item |
DELETE |
/items/{category}/{id} |
Delete an item |
GET |
/items/search?name=&category= |
Search items by name |
- Node.js v20+
- AWS CLI configured with credentials
- Serverless Framework v3
npm installnpm run offlineThe API will be available at http://localhost:3000.
# Deploy to dev stage (default)
npm run deploy
# Deploy to production
npm run deploy:prodcurl -X POST http://localhost:3000/dev/items \
-H "Content-Type: application/json" \
-d '{"name": "Wireless Mouse", "category": "electronics", "description": "Bluetooth mouse"}'curl http://localhost:3000/dev/items/electronicscurl http://localhost:3000/dev/items/electronics/{id}curl -X PUT http://localhost:3000/dev/items/electronics/{id} \
-H "Content-Type: application/json" \
-d '{"name": "Updated Name", "description": "Updated description"}'curl -X DELETE http://localhost:3000/dev/items/electronics/{id}# Search across all categories
curl "http://localhost:3000/dev/items/search?name=Mouse"
# Search within a specific category (more efficient)
curl "http://localhost:3000/dev/items/search?name=Mouse&category=electronics"├── serverless.yml # Serverless Framework configuration
├── package.json
├── src/
│ ├── handlers/
│ │ ├── createItem.js # POST /items
│ │ ├── getItem.js # GET /items/{category}/{id}
│ │ ├── listItems.js # GET /items/{category}
│ │ ├── searchItems.js # GET /items/search
│ │ ├── updateItem.js # PUT /items/{category}/{id}
│ │ └── deleteItem.js # DELETE /items/{category}/{id}
│ └── lib/
│ ├── dynamodb.js # DynamoDB client & single table key helpers
│ └── response.js # HTTP response helper
└── tests/
└── lib/
└── response.test.js
npm testMIT