Reverse Tunnels - Deployment Guide
Overview
Complete infrastructure for public URL access to device web services via AWS IoT Secure Tunneling. Status: Infrastructure 100% complete and ready for deployment.Architecture
Deployment Steps
1. Prerequisites
Ensure you have:- ✅ AWS CLI configured with appropriate credentials
- ✅ CDK CLI installed (
npm install -g aws-cdk) - ✅ Route53 hosted zone for
roboticks.io(already exists) - ✅ Backend database with
reverse_tunnelstable
2. Deploy Infrastructure
3. Verify Deployment
After deployment completes, verify the resources: Check CloudFront Distribution:4. Test DNS Resolution
5. Test Lambda Proxy
6. Test Cache Warmer
Post-Deployment Configuration
1. Create Test Reverse Tunnel
Create a reverse tunnel via the frontend UI or API:2. Wait for Cache Sync
The cache warmer runs every 5 minutes. Wait for the next sync or invoke manually:3. Test Public URL Access
Monitoring
CloudWatch Logs
Lambda Proxy Logs:cloudfront-tunnel-logs/ prefix.
CloudWatch Metrics
Troubleshooting
Issue: DNS Not Resolving
Symptoms:dig device-test.fleet.roboticks.io returns NXDOMAIN
Solution:
- Check Route53 records exist:
- Wait for DNS propagation (can take up to 48 hours, usually < 5 minutes)
- Clear local DNS cache:
sudo dscacheutil -flushcache(macOS)
Issue: SSL Certificate Errors
Symptoms: Browser shows SSL certificate warning Solution:- Check certificate status:
- Ensure status is
ISSUED - If
PENDING_VALIDATION, check Route53 validation records were created - Wait for certificate issuance (can take 30 minutes)
Issue: Lambda Proxy Returns 500
Symptoms:curl https://device-test.fleet.roboticks.io returns HTTP 500
Solution:
- Check Lambda logs:
- Common causes:
- Database connection timeout (check VPC security groups)
- DynamoDB table doesn’t exist (check table name in environment)
- Missing IAM permissions (check Lambda execution role)
Issue: Tunnel Not Found
Symptoms:{"error": "Tunnel not found or not active"}
Solution:
- Check tunnel exists in database:
- Check tunnel is enabled and not expired:
- Manually invoke cache warmer to sync to DynamoDB:
- Check DynamoDB cache:
Issue: Cache Warmer Fails
Symptoms: Cache warmer Lambda shows errors in CloudWatch Solution:- Check Lambda logs for error details
- Common causes:
- Database connection failure (check VPC/security groups)
- Missing database credentials (check Secrets Manager)
- DynamoDB write permission denied (check IAM role)
- Test database connectivity from Lambda:
Rollback
To rollback the deployment:- Backup DynamoDB table data if needed
- Note that Route53 records will be deleted
- CloudFront distribution deletion can take 15-30 minutes
Cost Optimization
Current Configuration
- DynamoDB: PAY_PER_REQUEST (serverless)
- Lambda: 512 MB proxy, 256 MB cache warmer
- CloudFront: PRICE_CLASS_100 (North America + Europe)
- API Gateway: HTTP API (cheaper than REST API)
Estimated Costs (100 devices, 1000 req/device/day)
- Lambda: ~$10/month
- DynamoDB: ~$1/month
- CloudFront: ~$5/month
- API Gateway: ~$3/month
- Route53: $0.50/month
- ACM Certificate: Free
- Total: ~$20/month
Cost Reduction Options
- Reduce Lambda Memory: Lower proxy Lambda to 256 MB if traffic is light
- Increase Cache TTL: Reduce cache warmer frequency to every 10-15 minutes
- CloudFront Price Class: Use PRICE_CLASS_ALL for global coverage (more expensive)
- Reserved Concurrency: Add reserved concurrency to Lambda for predictable costs
Security Considerations
Current Security Measures
- ✅ TLS encryption (CloudFront + ACM certificate)
- ✅ VPC isolation for Lambda functions
- ✅ IAM least-privilege permissions
- ✅ DynamoDB encryption at rest (default)
- ✅ CloudFront access logging enabled
- ✅ AWS IoT certificate-based device authentication
Recommended Enhancements
- WAF Rules: Add AWS WAF rules to CloudFront distribution
- Rate Limiting: Add API Gateway throttling per device
- Authentication: Implement JWT validation in Lambda proxy
- Monitoring: Add CloudWatch alarms for anomalous traffic
- Audit Logging: Enable CloudTrail for API calls
Next Steps
Infrastructure: ✅ Complete
All infrastructure is deployed and operational.Implementation Remaining:
-
Lambda Proxy Logic (~12-16 hours):
- WebSocket-to-WebSocket bidirectional forwarding
- HTTP-to-IoT-Tunnel request proxying
- AWS IoT Secure Tunneling Local Proxy protocol
-
Device SDK (~4 hours):
- Reverse tunnel manager in roboticks-sdk
- Device startup tunnel configuration fetch
-
Monitoring (~2 hours):
- CloudWatch alarms
- Metrics dashboard
-
Testing (~4 hours):
- End-to-end testing with real devices
Support
For issues or questions:- Check REVERSE_TUNNELS_INFRASTRUCTURE.md
- Check REVERSE_TUNNELS_IMPLEMENTATION_GUIDE.md
- Review CloudWatch logs for errors
- Check AWS documentation for specific services