Topics Covered in This Ruby on Rails Tutorial:
Creating Heroku & Amazon Web Services Accounts, Adding the Gems That Heroku Needs, Configuring Active Storage to Store Images on Amazon S3, Setting up AWS S3: Creating a Bucket & Security Keys, Deploying Our Code to Heroku
Exercise Overview
The moment every Rails developer anticipates has arrived: deploying your application to production where real users can access it. This transition from local development to live deployment represents a crucial milestone in your development journey.
Modern Rails applications have numerous hosting options, from specialized Rails platforms to self-managed cloud servers running Ubuntu or CentOS. You can configure your own EC2 instances, use containerized deployments with Docker, or leverage Platform-as-a-Service solutions. The landscape offers unprecedented flexibility for developers in 2026.
For this tutorial, we're using Heroku—a veteran platform that continues to excel at Rails deployment despite increased competition from services like Railway, Render, and Fly.io. Heroku's strength lies in its developer-friendly approach and robust Rails integration. However, Heroku's ephemeral filesystem means uploaded files don't persist between deployments, making external storage essential. This limitation actually reflects production best practices—separating application logic from static assets improves scalability and reliability.
We'll integrate Amazon Web Services (AWS) S3 for file storage while using Heroku for application hosting. This architecture mirrors what you'll encounter in professional Rails environments. Both services offer generous free tiers that accommodate learning projects and small-scale applications, though you'll want to monitor usage as your applications grow.
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.
Creating a Heroku Account & Installing Heroku Toolbelt
Before deploying to either platform, you'll need accounts with both Heroku and AWS. Let's start with Heroku, as it's typically the faster setup process.
Navigate to heroku.com in your browser
Click the Sign up for free button.
Complete the registration form with accurate information. Use an email address you can access immediately, as you'll need to verify it during this session.
Click Create Free Account to proceed.
Check your email for Heroku's confirmation message. If it doesn't appear in your inbox within a few minutes, check your spam or promotions folder.
Click the activation link in the email to verify your account.
Create a secure password when prompted, then click Set password and log in. Store this password securely—you'll need it for command-line authentication.
After successful login, you'll see your Heroku dashboard. Click Click here to proceed as (your email) to complete the setup process.
Open a new browser tab and navigate to toolbelt.heroku.com
Locate the Download and install section, copy the provided terminal command, paste it into your terminal, and press ENTER.
Run the installer and follow the installation prompts to install the Heroku CLI tools.
Heroku Setup Requirements
0/3Create Heroku account with accessible emailYou'll need to verify the account and access it during development
Install Heroku Toolbelt from toolbelt.heroku.comCommand-line interface for deploying and managing Heroku applications
Set secure password and document itRequired for Terminal authentication during deployment process
Other Hosting Options
While this tutorial focuses on Heroku and Amazon S3, the Rails hosting ecosystem has expanded significantly. We've chosen this combination for two compelling reasons:
- These platforms remain industry standards with extensive Rails community adoption.
- Both offer substantial free tiers perfect for learning and portfolio projects.
However, consider exploring alternatives as you advance. Railway and Render have emerged as modern competitors offering simpler pricing and better performance for many use cases. Engine Yard continues serving enterprise Rails applications with managed infrastructure. For maximum control, many production Rails apps run on cloud providers like Amazon EC2, Google Compute Engine, or DigitalOcean.
Cloud storage options have similarly diversified. Google Cloud Storage and Microsoft Azure Blob Storage offer competitive alternatives to S3, often with simpler pricing structures. Active Storage supports all major providers, making future migrations straightforward if your needs change.
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 |
Creating an Amazon Web Services (AWS) Account
AWS setup requires more verification steps than most services, but this thorough process ensures security for what will become your cloud infrastructure foundation.
Navigate to AWS.amazon.com in your browser.
IMPORTANT: Have your credit card and mobile phone ready before proceeding. While S3's free tier covers our tutorial usage, AWS requires payment method verification for all accounts. AWS will call your phone number during setup for identity verification—if you're in a classroom or quiet environment, ensure your phone is muted initially. Account activation can take up to 24 hours depending on verification complexity, so complete this step well before you need to deploy.
Click the Create a Free Account button to begin registration.
If you have an existing Amazon.com account, use those credentials for consistency.
If you're new to Amazon services or prefer separate accounts for AWS, enter your desired email address and select I am a new user.
Click Sign in using our secure server. New users should follow Amazon's account creation process completely.
Complete your contact information accurately, accept the AWS Customer Agreement, then click Create Account and Continue.
Enter your payment information. AWS requires valid payment methods even for free-tier usage. The Free Tier provides 5GB of S3 storage, 20,000 GET requests, and 2,000 PUT requests monthly for your first year—more than sufficient for learning projects. After the first year, S3 costs roughly $0.023 per GB monthly. For current pricing details, visit AWS.amazon.com/s3/pricing
Click Continue to proceed to identity verification.
Verify your phone number is correct on the Identity Verification screen, then click Call Me Now. Keep this browser window active.
AWS will call you within moments with an automated system. Enter the PIN displayed in your browser when prompted. You can use either your keypad or speak the numbers clearly. The call typically lasts under 30 seconds.
After successful verification, click Continue to select your Support Plan.
Keep Basic (Free) selected and click Continue. The free support plan includes documentation, whitepapers, and community forums.
Monitor your email for account activation confirmation. This usually arrives within minutes of completing registration.
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
Configuring Active Storage to Store Images on Amazon S3
Now we'll configure Rails to use different storage backends for different environments—a common pattern in professional Rails applications. Local storage works perfectly for development and testing, while production requires the reliability and scalability of cloud storage.
Return to your code editor and open your Rails project.
Open config > storage.yml. Locate the commented Amazon configuration section and modify it to match this configuration (changes in bold):
amazon: service: S3 access_key_id: <%= ENV['AWS_ACCESS_KEY_ID'] %> secret_access_key: <%= ENV['AWS_SECRET_ACCESS_KEY'] %> region: <%= ENV['S3_REGION'] %> bucket: <%= ENV['S3_BUCKET_NAME'] %>Using
ENVenvironment variables is a security best practice that keeps sensitive credentials out of your codebase. This approach prevents accidental credential exposure in version control and allows different environments to use different AWS resources.Open config > environments > production.rb and locate line 39. Update it to specify Amazon S3 for production storage:
# Store uploaded files on Amazon S3. config.active_storage.service = :amazonThis configuration ensures your production application uses S3 while development and test environments continue using local storage.
Save and close production.rb.
In your code editor, open your project's Gemfile.
Add the AWS SDK gem at the end of the file:
# AWS SDK for S3 integration with Active Storage gem 'aws-sdk-s3'The AWS SDK provides the interface between Rails and S3 services, handling authentication, file transfers, and error handling.
Save the Gemfile and return to your terminal.
Install the new gem by running:
bundle install
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
Creating a Git Repository
Heroku's deployment process relies entirely on Git, the industry-standard version control system. If you're not already using Git for your Rails projects, this is an excellent opportunity to establish that crucial habit. Even beyond deployment, Git is essential for professional Rails development.
NOTE: This section provides a Git quickstart for deployment purposes. For comprehensive Git workflows, consider dedicated Git training before working on team projects.
Switch to Terminal and navigate to your Rails project directory if you're not already there.
FIRST-TIME GIT USERS ONLY: Configure Git with your identity information:
git config --local user.name "Your Full Name" git config --local user.email "your.email@example.com"Use the same email address you used for your Heroku account to maintain consistency across platforms.
Initialize a new Git repository in your project directory:
git initThis creates a hidden
.gitdirectory containing all repository metadata. Your project is now ready for version control.Stage all project files for the initial commit:
git add .The period represents the current directory and all subdirectories. Git will include all source code, configuration files, and assets while respecting any
.gitignorerules.Create your initial commit with a descriptive message:
git commit -m "Initial commit: Rails application ready for deployment"Commit messages should clearly describe the changes. This practice becomes invaluable when reviewing project history or debugging issues months later.
Press Return to execute the commit. Git will confirm that all files have been successfully committed to your repository.
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
Setting up AWS S3: Creating a Bucket & Security Keys
With your AWS account ready, we'll now create the S3 infrastructure needed for file storage. This process involves creating a storage bucket and generating the security credentials Rails will use to access it.
Navigate to AWS.amazon.com in your browser
Click My Account / Console in the top-right corner of the page.
Select AWS Management Console from the dropdown. Sign in if prompted.
The AWS Console displays numerous service categories. Under the Storage section, click S3 to access Simple Storage Service.
Click the Create Bucket button to begin bucket creation.
In AWS terminology, a "bucket" is a container for objects (files) in S3. Each bucket has a globally unique name and can store unlimited objects up to 5TB each. Your free tier provides 5GB of storage across all buckets.
Accept the default Region selection unless you have specific latency requirements.
NOTE: For production applications, choose the region closest to your users' geographic location to minimize latency and potentially reduce costs.
Enter a globally unique Bucket Name. Since S3 bucket names must be unique across all AWS users worldwide, avoid generic names. Try something like rails-cookbook-yourname-2026 or cookbook-tutorial-uniquestring.
Click Create to create your bucket. If the name is already taken, try variations until you find an available name.
Record your bucket name securely—you'll need it for Heroku configuration.
Next, we'll generate API credentials that allow Heroku to securely access your S3 bucket. These credentials consist of an Access Key ID (public) and Secret Access Key (private).
Click your account name in the top-right corner of the AWS console.
Select Security Credentials from the dropdown menu.
AWS will display information about IAM (Identity and Access Management) best practices. For production applications, you should create dedicated IAM users with minimal required permissions rather than using root credentials.
For this tutorial, click Continue to Security Credentials to proceed with root access keys.
Expand the Access Keys (Access Key ID and Secret Access Key) section by clicking the + icon.
Click Create New Access Key to generate a new credential pair. Note that AWS limits accounts to two active access keys for security.
A modal dialog will display your new access keys.
Click Show Access Key to reveal both the Access Key ID and Secret Access Key.
CRITICAL: Click Download Key File immediately. AWS will never display the Secret Access Key again after you close this dialog. Store the downloaded file securely offline—treat it like a password.
TIP: The key file opens in spreadsheet applications like Excel. You can also copy both keys to a temporary text file for easier access during the next steps, but delete it afterward for security.
Close the modal and the AWS console tab. Your S3 infrastructure is now ready for integration.
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
Deploying Our Code to Heroku
With all prerequisites completed, we're ready to deploy your Rails application to Heroku's cloud platform. This process involves authenticating with Heroku, creating your application space, configuring environment variables, and pushing your code.
Return to Terminal and authenticate with Heroku:
heroku loginEnter the email address associated with your Heroku account when prompted, then press Return.
Type your Heroku password carefully. Terminal won't display characters as you type for security reasons. If you make an error, simply try again.
First-time authentication generates SSH keys on your local machine and registers them with Heroku, enabling secure code deployment without repeated password entry.
Create your Heroku application with:
heroku createHeroku assigns a random name like
mysterious-plateau-12345to avoid naming conflicts. This randomization is necessary since application names must be unique across Heroku's entire platform. You can rename your application later if desired.This command also adds a new Git remote named "heroku" to your repository, which enables deployment via
git push.Now configure Heroku with your AWS credentials. Have your S3 bucket name, Access Key ID, and Secret Access Key ready from the previous steps.
Set your S3 bucket name (don't press Return yet):
heroku config:set S3_BUCKET_NAME=Complete the command with your actual bucket name, for example:
heroku config:set S3_BUCKET_NAME=rails-cookbook-yourname-2026Press Return to save this environment variable.
Configure your AWS Access Key ID:
heroku config:set AWS_ACCESS_KEY_ID=Append your Access Key ID (the public key) and press Return to save it.
Configure your AWS Secret Access Key:
heroku config:set AWS_SECRET_ACCESS_KEY=Append your Secret Access Key (the private key) and press Return. Handle this key with extreme care—it provides full access to your AWS resources.
Set the AWS region to match your S3 bucket:
heroku config:set S3_REGION=us-east-1Deploy your application to Heroku:
git push heroku masterThis command may take several minutes on first deployment. Heroku receives your code, installs all gems specified in your Gemfile, compiles assets, and configures the runtime environment. You'll see detailed output showing each step's progress.
NOTE: If Terminal reports authenticity concerns about heroku.com, type yes and press Return to continue. If the connection fails, simply retry the push command.
Delete any temporary files containing your AWS credentials now that they're securely stored in Heroku's environment.
Run database migrations on your Heroku application:
heroku run rails db:migrateThe
heroku runprefix executes commands on Heroku's servers rather than locally. The output resembles local migration runs but occurs in your production environment.Open your live application directly from Terminal:
heroku openYour Rails application launches in your default browser, running live on Heroku's infrastructure and accessible to users worldwide!
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
Testing the Production Site and Syncing Your Database
Your application is now live, but thorough testing ensures everything functions correctly in the production environment. This is also an excellent time to understand the differences between development and production databases.
Verify full application functionality by creating a new recipe. Use content from your development testing or create something new, but be sure to include an image upload to test S3 integration. This test confirms that your Rails application, Heroku hosting, and AWS S3 storage are working together correctly.
Once you
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