aws eb deploy
Create a status controller and route for EB health checks
class StatusController < ApplicationController
def ping
render json: nil, status: :ok
end
end
Add route in config/routes: get '/ping' => 'status#ping'
Create ElasticCache cluster with 1 node, t2.micro or t2.small, 0 replication nodes
Create RDS node, postgres, with no multiAZ deployment, General SSD
I only use one database per RDS instance, but you could do multiple databases and have an integration and staging environment share the same RDS instance, I’ll write that up later.
Make sure the RDS instance is in the same VPC as the created Beanstalk environment, I usually disable the ability to connect to the RDS instance from outside the VPC.
Make sure the Security Group that is associated with the RDS instance can receive inbound traffic on port 5432 so you can connect from Beanstalk when you deploy the app
There are 3 options to create the database: (1) Name the main database on the instance what you want the Rails environment to use, for example my-app-staging
could be the database name, and you don’t have to create the database manually. (2) Connect to the EC2 instance and create the database using psql command line, or do it locally – I forward the RDS instance to localhost using the steps in this article (3) allow beanstalk to create the database using the configuration in your config/database.yml file of your rails app. I’ve had some issues doing this and usually have to create the database first before enabling migrations to run on future beanstalk deployments
For #2 – Using alias from article linked above, forward traffic from RDS instance port 5432 to localhost port 55432 my_app_rds
then run your psql create database commands
I recommend Option #1, naming the RDS db what you want to use for your app, it skips some configuration.
Install the elastic beanstalk CLI. This is not the aws cli subcommand elasticbeanstalk
, though that is an option, this will be brew install aws-elasticbeanstalk
(https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3.html)
eb init
— eb deploy
Zips local archive, deploys to selected environment
Additional option – configure a rake task yourself to deploy using Aws SDK for Ruby
create zip (backticks indicate ruby will run this as a shell command): git archive --format zip --output "#{app_name}-#{current_sha}.zip #{branch_name}`
Upload zip file to s3, get s3 URL of zip: s3_client = Aws::S3::Client.new()
Create Beanstalk Client, create an application version and tell it to update the environment to the newest application version
beanstalk = Aws::ElasticBeanstalk::Client.new
beanstalk.create_application_version()
beanstalk.update_environment()
These are essentially the same steps you get with eb deploy
but if you want more control over archive names, how branches are deployed, etc, this could be a good option.