graph TD
Client[Client] -->|HTTP Request| APIGateway[API Gateway]
APIGateway -->|Trigger| Lambda[Lambda Function]
Lambda -->|Cache Check| DynamoDB[(DynamoDB Cache)]
Lambda -->|Fetch Data| CoinGecko[CoinGecko API]
Lambda -->|Update Cache| DynamoDB
Lambda -->|Response| APIGateway
APIGateway -->|JSON Response| Client
style Client fill:#f9f,stroke:#333,stroke-width:2px
style APIGateway fill:#ff9900,stroke:#333,stroke-width:2px
style Lambda fill:#ff9900,stroke:#333,stroke-width:2px
style DynamoDB fill:#ff9900,stroke:#333,stroke-width:2px
style CoinGecko fill:#ff9900,stroke:#333,stroke-width:2px
# Clone & Install
git clone https://github.com/ozers/aws-sam-coin-lister.git
cd aws-sam-coin-lister/list-coins && npm install && cd ..
# Build & Deploy
sam build && sam deploy --guided
# Start local API
sam local start-api
# Test endpoints using curl
curl http://localhost:3000/coins/list
curl http://localhost:3000/coins/bitcoin
curl http://localhost:3000/coins/bitcoin/history
-
Import the Postman collection:
# Collection location docs/aws-sam-coin-lister.postman_collection.json
-
Set up environment variables in Postman:
baseUrl
:http://localhost:3000
(for local testing)prodUrl
:https://{api-id}.execute-api.{region}.amazonaws.com/Prod
(for production)
-
Available requests:
- List All Coins:
GET {{baseUrl}}/coins/list?page=1&per_page=100
- Get Coin Details:
GET {{baseUrl}}/coins/bitcoin
- Get Coin History:
GET {{baseUrl}}/coins/bitcoin/history
- List All Coins:
# Test with event file
sam local invoke ListCoinsFunction -e events/event.json
# Available test event
events/event.json # List coins
Endpoint | Method | Cache TTL | Description |
---|---|---|---|
/ping |
GET | 5 min | Health check endpoint |
/coins/list |
GET | 30 min | List all coins with pagination |
/coins/{coinId} |
GET | 5 min | Get specific coin details |
/coins/{coinId}/history |
GET | 1 hour | Get coin price history |
# Health check
curl https://{api-id}.execute-api.{region}.amazonaws.com/Prod/ping
# List coins
curl https://{api-id}.execute-api.{region}.amazonaws.com/Prod/coins/list?page=1&per_page=100
# Get Bitcoin details
curl https://{api-id}.execute-api.{region}.amazonaws.com/Prod/coins/bitcoin
- π¦ Serverless: AWS SAM, Lambda, API Gateway
- πΎ Cache: DynamoDB
- π Data: CoinGecko API
- π§ͺ Testing: Jest
- AWS Account & SAM CLI
- Node.js 18.x
- Docker (optional)
- Postman (optional, for API testing)
# Delete stack
sam delete
# Verify
aws cloudformation describe-stacks --stack-name sam-app
- Cache Errors: Normal during testing
- Deployment Issues: Check AWS credentials & IAM
- API Issues: Verify API ID & region
- Fork & Clone
- Create feature branch
- Commit & Push
- Create PR