How to deploy Solidus to AWS like a Boss
In this tutorial, we will guide you through the process of deploying a Solidus eCommerce application on Amazon AWS Elastic Beanstalk, a leading cloud computing platform. At BRADIENT, we use both Solidus and AWS to deliver top-quality eCommerce websites for our clients.
To deploy a Solidus application on AWS Elastic Beanstalk, you will need to meet the following requirements:
- An AWS account
- The AWS Elastic Beanstalk command line interface (CLI) installed on your local machine
- A Solidus application ready for deployment
- A configuration file for AWS Elastic Beanstalk
Once you have these requirements in place, you can follow the steps in this tutorial to successfully deploy your Solidus eCommerce application on AWS Elastic Beanstalk. This tutorial will cover all the necessary steps, including creating an AWS Elastic Beanstalk environment, uploading your application code, and testing your application. With the help of this tutorial, you will be able to smoothly deploy your Solidus application on AWS Elastic Beanstalk and take advantage of all the benefits this powerful platform has to offer.
Here are the requirements:
- Installed and configured Elastic Beanstalk vía the command line interface (EB CLI)
- Rails (version 5.2.0 was used to write this article)
- Git
- Ruby, 2.5.1, Rails, 5.2.0, Solidus, v2.6.0
Install and configure your eCommerce locally:
First of all, like you did a thousand times, create your new Rails application:
> gem install pg
> rails new dope_ecommerce_store --database=postgresql
> cd dope_ecommerce
Install the required Solidus gem. Simply add the following lines to your Gemfile:
> vim Gemfile
add:
gem 'solidus', '~> 2.6.0'
gem 'solidus_auth_devise'
gem 'aws-sdk', '~> 2.3' > bundle
Note that we are also specifying the aws-sdk gem; this is needed if we want to use S3.
Edit your config/database.yml and add the database configuration:
add:
production:
<<: *default
adapter: postgresql
encoding: unicode
database: <%= ENV['RDS_DB_NAME'] %>
username: <%= ENV['RDS_USERNAME'] %>
password: <%= ENV['RDS_PASSWORD'] %>
host: <%= ENV['RDS_HOSTNAME'] %>
port: <%= ENV['RDS_PORT'] %>
Install and run migrations on Solidus:
> bundle
> bundle exec rake db:create
> bundle exec rails g spree:install
> bundle exec rails g solidus:auth:install
> bundle exec rake railties:install:migrations
> bundle exec rake db:migrate
Initialize your project and make your first commit in Git:
> git init
> git add .
> git commit -m 'Initial project'
Run bundle exec rails s then go to http://localhost:3000 and make sure you correctly visualize the homepage.
> bundle exec rails s
Configure Elastic Beanstalk
Ok, let’s start running some commands using EB CLI Commands. Then you can initiate a new Environment application with the following:
> eb init
Note: If you are using a separate AWS account use this instead to specify the AWS profile name:
> eb init --profile profile_name
Select this option: 4) Ruby 2.4 (Puma)
Configure your AWS Elastic Beanstalk (EB) Extensions:
> mkdir .ebextensions
> cd .ebextensions
> touch 01_packages.config
> touch 02_nginx.config
Include your EB Extensions configurations, please make sure that you copy and paste correctly since these are space sensitive.
> vim .ebextensions/01_packages.config
add:
packages:
yum:
git: []
ImageMagick: []
ImageMagick-devel: []
openssl-devel: []
postgresql93-devel: []
Create your NGINX configuration file for AWS Elastic Beanstalk (EB) Extensions:
> vim .ebextensions/02_nginx.config
add:
files:
"/etc/nginx/conf.d/01_proxy.conf":
mode: "000644"
owner: root
group: root
content: |
client_max_body_size 100M;
container_commands:
reload_nginx:
command: "sudo service nginx reload"
Commit your changes by running the following git commands:
> git add .
> git commit -m "message commit"
> git push origin master
Create your .ENV keys:
At the root of your app:
> touch .env
> vim .env
add:
SECRET_KEY_BASE=653.................8556
AWS_BUCKET=S3BucketName
AWS_ACCESS_KEY_ID=A.........8Q
AWS_SECRET_ACCESS_KEY=qx.......Gp
AWS_REGION=us-west-2
Now you can deploy your project to AWS Elastic Beanstalk (EB) that you created by utilizing the set env keys method with the following command:
> eb create domainName-development -c subdomain-name -r us-west-2 -k key_name -db.i db.t2.micro -db.engine postgres -db.user rds_username -db.pass rds_password -db.size 5 --scale 1 --elb-type classic --debug --verbose && eb setenv SECRET_KEY_BASE=653.................8556 && eb setenv AWS_BUCKET=S3BucketName && eb setenv AWS_ACCESS_KEY_ID=A.........8Q && eb setenv AWS_SECRET_ACCESS_KEY=qx.......Gp && eb setenv AWS_REGION=us-west-2 --profile profile_name --verbose && eb deploy --profile profile_name --verbose --debug
Note: Once again if you are utilizing multiple AWS Profiles you can pass in the profile at the end of the above command as shown above with the following value :
--profile profile_name
DONE
Take the first step to achieving your goals
Fill out the form below and we will contact you shortly.