Infrastructure as Code for Smalruby APIs using AWS SAM (Serverless Application Model).
Overview
This repository contains AWS SAM templates and related infrastructure configurations for managing Smalruby APIs, including:
- cors-proxy: General-purpose proxy for various URLs with CORS issues
- scratch-api-proxy: Proxy for calling Scratch APIs that cannot be called directly due to CORS restrictions
- mesh-zone: Generate identity from gateway IPv4 address for Smalruby Mesh
Structure
template.yaml: Main SAM template defining API Gateway and Lambda functionslambda/: Lambda function source code directoriesscripts/: Deployment and utility scriptsexported-configs/: Exported configurations from existing AWS resourcessamconfig.toml: SAM configuration file
Lambda Functions
- smalruby-cors-proxy: General-purpose CORS proxy
- smalruby-mesh-zone-get: Mesh zone domain generation
- smalruby-scratch-api-proxy-translate: Scratch translate API proxy
- smalruby-scratch-api-proxy-get-project-info: Scratch project info API proxy
- cors-for-smalruby: CORS handler for Smalruby
Prerequisites
- AWS CLI configured with appropriate credentials
- SAM CLI installed
- Ruby 3.4 runtime (for local testing)
Installation
Install SAM CLI
# macOS brew install aws-sam-cli # Or pip pip install aws-sam-cli
Usage
Local Testing
ローカルでLambda関数をテストするには、LOCAL_TESTING.mdを参照してください。
# 個別の関数をテスト ./test-local.sh CorsForSmalrubyFunction # すべての関数をテスト ./test-all-local.sh # ローカルAPI Gatewayを起動 ./start-local-api.sh # API エンドポイントをテスト ./test-api-endpoints.sh
Export Existing Configurations
./scripts/export-config.sh
Local Development and Testing
# Build the application sam build # Start local API for testing ./scripts/local-test.sh # or sam local start-api # Test specific function sam local invoke SmalrubyCorsProxyFunction --event events/cors-proxy-event.json
Deployment
# Deploy to AWS ./scripts/deploy.sh # or sam build && sam deploy
API Endpoints
After deployment, the following endpoints will be available:
GET /cors-proxy- General CORS proxyGET /mesh-domain- Mesh zone domain generationGET /scratch-api-proxy/translate- Scratch translate proxyGET /scratch-api-proxy/projects/{projectId}- Scratch project info proxy
Configuration
- Stack Name:
smalruby-infrastructure - Region:
ap-northeast-1(Tokyo) - Stage:
prod - Domain:
api.smalruby.app
Development Notes
- Lambda functions are currently placeholder implementations
- Actual function code should be retrieved from existing Lambda functions
- All functions use Ruby 3.4 runtime with ARM64 architecture
- CORS headers are configured for cross-origin requests