Skip to content

How to deploy a serverless tarot card reading API using Lambda and API Gateway?

0

I'm building a free tarot card reading API that serves all 78 tarot card meanings (Major and Minor Arcana) with upright/reversed interpretations. I want to deploy it as a serverless application on AWS.

My requirements:

  • Python Lambda function with API Gateway
  • Endpoints for random card draws, daily tarot card, yes/no readings, and three-card spreads
  • CORS enabled for cross-origin access
  • Low cost (mostly free tier)

I've already published it to the AWS Serverless Application Repository (tarot-card-meanings-api) and also created a CDK construct (cdk-tarot-reading-api on NPM), but I'm wondering about best practices for:

  1. Should I use REST API or HTTP API for API Gateway?
  2. What's the recommended memory/timeout for a simple JSON response Lambda?
  3. Any tips for keeping cold starts minimal?

The project is open source: https://github.com/gokimedia/tarot-reading Live demo: https://deckaura.com/pages/free-tarot-reading

asked a month ago40 views
2 Answers
1

After testing different approaches, here's what worked best for my tarot card API:

1. HTTP API vs REST API I went with HTTP API (v2) — it's ~70% cheaper and has lower latency for simple JSON APIs. REST API is better if you need request validation, API keys, or usage plans.

2. Lambda Configuration For a simple Python function returning JSON from an in-memory dataset (78 tarot cards), 128MB memory and 10s timeout is more than enough. Average response time is under 50ms.

3. Cold Start Optimization

  • Keep the function small (single file, no heavy dependencies)
  • Use Python 3.12 runtime (faster cold starts than 3.9)
  • The dataset is embedded in the code, so no external DB calls needed

Deployment Options I've set up:

  • SAR (one-click deploy): Search "tarot-card-meanings-api" in the Serverless Application Repository
  • CDK construct: npm install cdk-tarot-reading-api — deploys Lambda + API Gateway in 3 lines of code
  • Docker: Available on ECR Public Gallery

Resources:


repost.aws adresine gidip yapıştırın. Hem soru hem cevap sizin hesabınızdan olabilir — "self-answered question" re:Post'ta normal.

answered a month ago
EXPERT
reviewed a month ago
0

Based on AWS best practices for serverless APIs, here are recommendations for your tarot card reading API:

1. REST API vs HTTP API: For your use case, an HTTP API is recommended. HTTP APIs offer minimal features at a lower cost compared to REST APIs, making them ideal for straightforward serverless applications. Since you're focused on keeping costs low and your API serves JSON responses without complex authorization requirements, HTTP API would be the better choice.

2. Memory and Timeout Configuration: For a Lambda function that returns simple JSON responses (like tarot card meanings), you can start with minimal settings:

  • Memory: 128-256 MB should be sufficient for basic JSON operations
  • Timeout: 3-10 seconds is typically adequate for simple data retrieval and response formatting

Since Lambda pricing is based on execution time and memory allocation, starting with lower values and monitoring performance will help optimize costs while staying within the free tier.

3. Minimizing Cold Starts: To reduce cold start impact:

  • Optimize function performance by keeping your deployment package small and minimizing dependencies
  • Handle cold starts gracefully in your code design
  • Manage dependencies efficiently - only include what's necessary for your tarot card data and logic
  • Consider the trade-off between memory allocation and execution speed, as higher memory can sometimes reduce cold start duration

For monitoring and debugging, use AWS CloudWatch to gain insights into your function's execution patterns and identify any performance bottlenecks. This will help you fine-tune your configuration based on actual usage patterns.

Since your API primarily serves static tarot card data with interpretations, the serverless architecture with Lambda and API Gateway is well-suited for handling variable request loads while keeping costs minimal.
Sources
Get started with API Gateway - Amazon API Gateway
Community | Demystifying AWS Lambda: Deep Dive into Serverless Computing

answered a month ago
EXPERT
reviewed a month ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.