Hey mate, I need a simple app that makes a request to a REST endpoint, gets the response…
- User
Hey mate, I need a simple app that makes a request to a REST endpoint, gets the response (JSON) and stores it in Redis instance. It should run on a schedule (let's say once per hour). How can I implement such a solution using AWS services? Provide me with a few examples, describe every example, try to get as simple setups as possible. Thanks!
Assistant
Hey! 👋 You've got a pretty straightforward use case, and AWS gives you several ways to do this. Since your goal is to:
- Make an HTTP request to a REST endpoint
- Get JSON data
- Store it in Redis
- Run this on a schedule (e.g., every hour)
Let’s go through three simple setups using AWS services — each one increasing slightly in complexity but still minimal.
✅ Example 1: AWS Lambda + EventBridge (CloudWatch Events) + ElastiCache Redis
🔧 What It Does:
This setup uses AWS Lambda to run your code that fetches the JSON and stores it in Redis. An EventBridge rule triggers the Lambda hourly.
📦 Components:
- Lambda: Runs your Python/Node.js/etc function.
- EventBridge Rule: Triggers Lambda once per hour.
- ElastiCache Redis: Your Redis instance (can be Redis or Redis Cluster).
🚀 How to Set Up:
Step 1: Create Redis Instance
- Go to Amazon ElastiCache
- Launch a Redis instance (you can choose "Redis single-node" for simplicity).
- Note down the endpoint (e.g.,
myredis.cache.amazonaws.com).
Step 2: Write Lambda Function
Here's a basic example in Python:
import os import json import requests import redis def lambda_handler(event, context): # Fetch from REST API response = requests.get("https://api.example.com/data") data = response.json() # Connect to Redis r_host = os.getenv("REDIS_HOST") r = redis.Redis(host=r_host, port=6379, db=0) # Store JSON r.set("my_key", json.dumps(data)) return {"statusCode": 200, "body": "Stored in Redis"}You'll need to package dependencies like
requestsandredisinto a Lambda Layer or ZIP file.Step 3: Configure Lambda
- Add environment variable:
REDIS_HOST→ your ElastiCache endpoint. - Ensure Lambda has VPC access if Redis is inside a VPC.
Step 4: Schedule with EventBridge
- Create a new Rule under EventBridge > Rules.
- Choose Schedule expression:
rate(1 hour) - Target your Lambda function.
💡 Pros:
- Fully serverless
- Pay only when it runs
- Easy to scale
🛑 Cons:
- Cold starts (rarely affects scheduled functions)
- Need to handle dependencies (like
redislib)
✅ Example 2: EC2 Instance + Cron Job + Redis
🔧 What It Does:
Use a small EC2 instance running a script hourly via cron job.
📦 Components:
- EC2: Hosts your script.
- Cron: Schedules the job.
- ElastiCache Redis: As before.
🚀 How to Set Up:
Step 1: Launch a Small EC2 Instance
- Use Amazon Linux or Ubuntu.
- Allow outbound internet access.
- If Redis is in a VPC, ensure connectivity.
Step 2: Install Dependencies
SSH into the instance:
sudo yum install python3 pip -y pip3 install requests redisStep 3: Write the Script
Same as the Lambda function above, just saved as a
.pyfile.Step 4: Schedule with Cron
Edit crontab:
crontab -eAdd:
0 * * * * /usr/bin/python3 /home/ec2-user/fetch_and_store.py >> /var/log/myapp.log 2>&1💡 Pros:
- Very simple to debug
- No packaging needed for Lambda-like constraints
🛑 Cons:
- Always-on instance = ongoing cost
- Less scalable
✅ Example 3: AWS Fargate Task + EventBridge Scheduler
🔧 What It Does:
Runs a Docker container (with your app) once per hour using Fargate and EventBridge Scheduler.
📦 Components:
- Docker image: With your app logic
- Fargate Task: Runs the container
- EventBridge Scheduler: Triggers task hourly
- ElastiCache Redis: Same as before
🚀 How to Set Up:
Step 1: Create Docker Image
Your Dockerfile might look like:
FROM python:3.9-slim WORKDIR /app COPY . . RUN pip install -r requirements.txt CMD ["python", "fetch_and_store.py"]Push to ECR (Elastic Container Registry).
Step 2: Create Fargate Task Definition
Define a task that pulls your image and sets environment variables (like Redis host).
Step 3: Create EventBridge Scheduler
- Create a new schedule.
- Choose Target: ECS task
- Select your cluster and task definition
- Set schedule:
rate(1 hour)
💡 Pros:
- Good for containerized apps
- More control over runtime than Lambda
🛑 Cons:
- More complex than Lambda
- Still some infrastructure to manage
🧠 Summary Table
Setup Service Used Cost-Efficient? Simplicity Scalability Lambda + EventBridge ✅ Serverless 💰 Yes 🟢 Easy 🟢 Auto-scaling EC2 + Cron ❌ Always-on 💸 Moderate 🟢 Easy 🔴 Manual Fargate + Scheduler ⚠️ Hybrid 💵 Medium 🟡 Medium 🟢 Auto-scaling
✅ Recommendation:
For simplicity, cost-efficiency, and ease of maintenance, go with:
👉 AWS Lambda + EventBridge + ElastiCache Redis
You’ll write a small function, set up a timer, and store the result. That’s all!
If you want, I can help you generate a full deployable Lambda ZIP with dependencies included. Just say the word! 😊
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.