Automated scripts to scale Render services using the Render API.
This repository contains two scripts for scaling Render services:
- scale_service.py - Full-featured Python script with advanced options
- scale_service.sh - Quick bash wrapper for simple scaling operations
- Render API Key (get from your Render dashboard)
- For Python script: Python 3.6+ (uses only standard library)
- For Bash script: bash, curl (jq optional for pretty output)
Set your Render API key as an environment variable:
export RENDER_API_KEY="rnd_your_api_key_here"Or pass it directly via the --api-key flag (Python script only).
- Absolute scaling (set to specific instance count)
- Relative scaling (increase/decrease by N instances)
- Dry-run mode to preview changes
- Verbose output for debugging
- Fetches current service state before scaling
- Comprehensive error handling
Scale to absolute number of instances:
python scale_service.py --service-id srv-abc123 --num-instances 5Increase by relative number:
python scale_service.py --service-id srv-abc123 --increase-by 2Decrease by relative number:
python scale_service.py --service-id srv-abc123 --decrease-by 1Dry run (preview without making changes):
python scale_service.py --service-id srv-abc123 --num-instances 10 --dry-runVerbose output:
python scale_service.py --service-id srv-abc123 --num-instances 5 --verboseWith explicit API key:
python scale_service.py --service-id srv-abc123 --num-instances 5 --api-key rnd_xyz789--service-id Render service ID (required)
--num-instances Absolute number of instances to scale to
--increase-by Number of instances to increase by
--decrease-by Number of instances to decrease by
--api-key Render API key (or use RENDER_API_KEY env var)
--dry-run Preview changes without executing
--verbose, -v Enable verbose output
- Simple and fast
- Single command scaling
- Minimal dependencies
./scale_service.sh <service-id> <num-instances>export RENDER_API_KEY="rnd_xyz789"
./scale_service.sh srv-abc123 5Your service ID can be found in the Render Dashboard URL when viewing a service:
https://dashboard.render.com/web/srv-abc123def456
^^^^^^^^^^^^^^^
This is your service ID
Or use the Render API to list your services:
curl -H "Authorization: Bearer $RENDER_API_KEY" \
https://api.render.com/v1/servicesScale up during business hours, scale down at night:
# Scale up at 8 AM to 5 instances
0 8 * * * /path/to/scale_service.sh srv-abc123 5
# Scale down at 6 PM to 1 instance
0 18 * * * /path/to/scale_service.sh srv-abc123 1Scale before deployment, scale back after:
# Example GitHub Actions
- name: Scale up before deployment
run: |
python scale_service.py --service-id ${{ secrets.SERVICE_ID }} --num-instances 5
env:
RENDER_API_KEY: ${{ secrets.RENDER_API_KEY }}Combine with monitoring to auto-scale based on load:
#!/bin/bash
# Check CPU usage and scale accordingly
CPU_USAGE=$(get_cpu_usage_from_monitoring)
if [ "$CPU_USAGE" -gt 80 ]; then
python scale_service.py --service-id srv-abc123 --increase-by 2
elif [ "$CPU_USAGE" -lt 20 ]; then
python scale_service.py --service-id srv-abc123 --decrease-by 1
fiThe scripts use the Render API v1:
- Endpoint:
POST https://api.render.com/v1/services/{serviceId}/scale - Headers:
Authorization: Bearer {apiKey}Content-Type: application/json
- Body:
{"numInstances": <number>}
Documentation: https://api-docs.render.com/
Both scripts provide clear error messages for common issues:
- Missing or invalid API key
- Service not found
- Invalid instance count
- API rate limiting
- Network errors
Authentication Failed:
- Verify your API key is correct
- Check that the key has not expired
- Ensure the key has appropriate permissions
Service Not Found:
- Verify the service ID is correct
- Confirm the service exists in your account
Rate Limiting:
- The Render API has rate limits
- Add delays between multiple scaling operations
- Never commit API keys to version control
- Use environment variables or secret management systems
- Restrict API key permissions to minimum required
- Rotate API keys regularly
These scripts are provided as-is for internal use.