Deployment Guide
Deploy the SG Cars Trends API to production using SST and AWS
Overview
The SG Cars Trends API is deployed using SST (Serverless Stack) on AWS with infrastructure as code. This guide covers deployment strategies, environments, and best practices.
Infrastructure Architecture
AWS Services Used
AWS Lambda
Serverless functions for API endpoints and workflows
Amazon RDS
PostgreSQL database for data storage
CloudFront
CDN for API distribution and caching
Route 53
DNS management and domain routing
API Gateway
HTTP API management and routing
Systems Manager
Secure parameter storage for secrets
Architecture Diagram
Deployment Environments
Environment Overview
Environment | Purpose | Domain | Database |
---|---|---|---|
Development | Local development | localhost:3000 | Local PostgreSQL |
Staging | Pre-production testing | api-staging.sgcarstrends.com | AWS RDS (staging) |
Production | Live API | api.sgcarstrends.com | AWS RDS (production) |
Environment Configuration
Prerequisites
1. AWS Account Setup
AWS Account
Create an AWS account and configure billing
IAM User
Create an IAM user with necessary permissions
AWS CLI
Install and configure AWS CLI
Domain Setup
Configure domain in Route 53 (optional)
2. Required Permissions
The deployment requires the following AWS permissions:
Core Services
Core Services
- Lambda: Create, update, delete functions
- API Gateway: Create, update HTTP APIs
- CloudFormation: Create, update stacks
- IAM: Create, update roles and policies
Database & Storage
Database & Storage
- RDS: Create, manage PostgreSQL instances
- Systems Manager: Create, read parameters
- CloudWatch: Create logs and metrics
Networking
Networking
- VPC: Create, manage virtual networks
- Route 53: Manage DNS records
- CloudFront: Create distributions
3. Environment Variables
Set up deployment-specific environment variables:
Deployment Process
1. Initial Deployment
2. Database Migration
3. Verification
After deployment, verify the API:
SST Stack Configuration
API Stack
Database Stack (Optional)
CI/CD Pipeline
GitHub Actions Workflow
Deployment Scripts
Production Configuration
Performance Optimization
Database Configuration
Security Configuration
Monitoring and Logging
CloudWatch Configuration
Application Logging
Rollback Procedures
Automated Rollback
Manual Rollback
Troubleshooting
Common Deployment Issues
Lambda Function Timeout
Lambda Function Timeout
Symptoms: Function timing out after 30 seconds
Solutions:
- Increase timeout in SST configuration
- Optimize database queries
- Add connection pooling
- Check external API response times
Database Connection Issues
Database Connection Issues
Symptoms: Database connection refused or timeout
Solutions:
- Check security group rules
- Verify database endpoint and credentials
- Check VPC configuration
- Monitor connection pool usage
API Gateway 5xx Errors
API Gateway 5xx Errors
Symptoms: 500/502/503 errors from API Gateway
Solutions:
- Check Lambda function logs
- Verify function permissions
- Check timeout configurations
- Monitor memory usage
Domain Certificate Issues
Domain Certificate Issues
Symptoms: SSL certificate validation failing
Solutions:
- Verify DNS records in Route 53
- Check certificate status in ACM
- Ensure domain ownership validation
- Wait for DNS propagation
Debugging Tools
Cost Optimization
Cost Monitoring
Lambda Optimization
- Use ARM64 architecture
- Right-size memory allocation
- Optimize cold start times
- Monitor invocation patterns
Database Optimization
- Use Aurora Serverless for variable workloads
- Enable auto-pause for staging
- Optimize queries and indexes
- Monitor connection usage
Data Transfer
- Use CloudFront for caching
- Optimize response sizes
- Enable compression
- Monitor bandwidth usage
Storage
- Use S3 for static assets
- Implement data lifecycle policies
- Archive old data
- Monitor storage usage