Deployment with Heroku & AWS S3
Deploy Rails Applications with Heroku and AWS
Core Deployment Technologies
Heroku Platform
Web hosting service specializing in easily deploying Ruby on Rails applications with built-in scaling and management tools.
AWS S3 Storage
Amazon's cloud storage service for handling user-uploaded content like images and files with global accessibility.
Active Storage
Rails framework component that manages file uploads and integrates seamlessly with cloud storage providers.
Heroku handles application hosting while AWS S3 manages file storage because Heroku doesn't support user file uploads on their system. This separation creates a robust, scalable architecture.
Rails Hosting Platforms
| Feature | Heroku | Engine Yard | AWS EC2 |
|---|---|---|---|
| Ease of Use | Very Easy | Easy | Complex |
| Rails Integration | Excellent | Excellent | Manual |
| Free Tier | Yes | Limited | Yes |
| Configuration | Minimal | Guided | Full Control |
AWS requires a valid credit card and phone verification even for free tier usage. Account creation can take up to 24 hours with bank validation, so complete this step well in advance.
AWS Account Creation Process
Initial Registration
Visit AWS.amazon.com and create account with email and contact information
Payment Verification
Enter credit card details for account verification (no charges for free tier usage)
Identity Verification
Complete automated phone verification by entering the PIN displayed in browser
Support Plan Selection
Choose Basic (Free) support plan to complete account setup
Using ENV variables for AWS credentials keeps sensitive information secure and allows different configurations for development, testing, and production environments.
Active Storage Configuration Steps
Configure service with environment variables for secure credential management
Change active_storage.service to :amazon for production environment
Required dependency for Rails to communicate with Amazon S3 service
Install the new gem and update the application bundle
Git Repository Setup
Configure Git User
Set local user name and email for commit attribution (first-time users only)
Initialize Repository
Run 'git init' to create empty repository in current directory
Stage All Files
Use 'git add .' to add entire cookbook folder contents to repository
Initial Commit
Commit changes with descriptive message using 'git commit -m' command
Download and securely store your access keys immediately. The secret access key cannot be retrieved again once the modal is closed. Store keys offline in a secure location.
S3 Bucket and Keys Setup
Create S3 Bucket
Access S3 service and create uniquely named bucket for file storage
Generate Access Keys
Create new access key pair from Security Credentials section
Download Key File
Immediately download and securely store both access key ID and secret key
Heroku Deployment Process
Heroku Login
Authenticate with Heroku using email and password credentials
Create Heroku App
Generate new Heroku application with random name
Configure Environment Variables
Set S3 bucket name, AWS access keys, and region using heroku config:set
Push Code to Heroku
Deploy application code using 'git push heroku master' command
Run Database Migration
Execute 'heroku run rails db:migrate' to set up production database
Your Rails application is now live on Heroku with AWS S3 file storage. The site is accessible worldwide and ready for testing with full functionality including file uploads.
Post-Deployment Verification
Launches production site in default browser for immediate testing
Verify all features work correctly in production environment
Confirm images and files are properly stored in AWS S3
Test creating, reading, updating, and deleting records
Key Takeaways