Deploying a Rails 5 App using Elastic Beanstalk and PostgreSQL

What is Elastic Beanstalk?

Getting Started

$ brew update
$ brew install awsebcli
$ eb --version
EB CLI 3.2.2 (Python 3.4.3)
$ eb init
Select a default region
1) us-east-1 : US East (N. Virginia)
2) us-west-1 : US West (N. California)
3) us-west-2 : US West (Oregon)
4) eu-west-1 : EU (Ireland)
5) eu-central-1 : EU (Frankfurt)
6) ap-south-1 : Asia Pacific (Mumbai)
7) ap-southeast-1 : Asia Pacific (Singapore)
8) ap-southeast-2 : Asia Pacific (Sydney)
9) ap-northeast-1 : Asia Pacific (Tokyo)
10) ap-northeast-2 : Asia Pacific (Seoul)
11) sa-east-1 : South America (Sao Paulo)
12) cn-north-1 : China (Beijing)
13) us-east-2 : US East (Ohio)
14) ca-central-1 : Canada (Central)
15) eu-west-2 : EU (London)
(default is 3):
Select an application to use
1) AnotherAppIPreviouslyDeployed
2) [ Create new Application ]
(default is 2): 2
Enter Application Name
(default is "myapp"):
Application myapp has been created.
It appears you are using Ruby. Is this correct?
(Y/n): y
Select a platform version.
1) Ruby 2.3 (Puma)
2) Ruby 2.2 (Puma)
3) Ruby 2.1 (Puma)
4) Ruby 2.0 (Puma)
5) Ruby 2.3 (Passenger Standalone)
6) Ruby 2.2 (Passenger Standalone)
7) Ruby 2.1 (Passenger Standalone)
8) Ruby 2.0 (Passenger Standalone)
9) Ruby 1.9.3
(default is 1): 1
Do you want to set up SSH for your instances?

Setting up the Enviornment

$ eb create myapp-env
Creating application version archive "app-170629_125010".
Uploading myapp/app-170629_125010.zip to S3. This may take a while.
Upload Complete.
Environment details for: myapp-env
Application name: myapp
Region: eu-west-2
Deployed Version: app-170629_125010
Environment ID: e-r4aeg3mdhp
Platform: arn:aws:elasticbeanstalk:eu-west-2::platform/Puma with Ruby 2.3 running on 64bit Amazon Linux/2.4.1
Tier: WebServer-Standard
CNAME: UNKNOWN
Updated: 2017-06-29 11:50:15.449000+00:00
Printing Status:
INFO: createEnvironment is starting.
INFO: Using elasticbeanstalk-eu-west-2-677471806624 as Amazon S3 storage bucket for environment data.
INFO: Created security group named: sg-6aa8d203
INFO: Created load balancer named: awseb-e-r-AWSEBLoa-1HFNDWZGG06GC
INFO: Created security group named: awseb-e-r4aeg3mdhp-stack-AWSEBSecurityGroup-4BVER9RZTAEA
INFO: Created Auto Scaling launch configuration named: awseb-e-r4aeg3mdhp-stack-AWSEBAutoScalingLaunchConfiguration-BGBXSRWXV2CS
INFO: Environment health has transitioned to Pending. Initialization in progress (running for 30 seconds). There are no instances.
INFO: Created Auto Scaling group named: awseb-e-r4aeg3mdhp-stack-AWSEBAutoScalingGroup-16TMUTO9XH2LD
INFO: Waiting for EC2 instances to launch. This may take a few minutes.
INFO: Created Auto Scaling group policy named: arn:aws:autoscaling:eu-west-2:677471806624:scalingPolicy:3554965a-0856-4f3c-90be-cb49bace9305:autoScalingGroupName/awseb-e-r4aeg3mdhp-stack-AWSEBAutoScalingGroup-16TMUTO9XH2LD:policyName/awseb-e-r4aeg3mdhp-stack-AWSEBAutoScalingScaleUpPolicy-1NDWK7HFTSWWT
INFO: Created Auto Scaling group policy named: arn:aws:autoscaling:eu-west-2:677471806624:scalingPolicy:2e1bac83-9f60-41ca-b60d-70e83fe14992:autoScalingGroupName/awseb-e-r4aeg3mdhp-stack-AWSEBAutoScalingGroup-16TMUTO9XH2LD:policyName/awseb-e-r4aeg3mdhp-stack-AWSEBAutoScalingScaleDownPolicy-56CUZI6KKCGU
INFO: Created CloudWatch alarm named: awseb-e-r4aeg3mdhp-stack-AWSEBCloudwatchAlarmHigh-MXF54IOA2SZX
INFO: Created CloudWatch alarm named: awseb-e-r4aeg3mdhp-stack-AWSEBCloudwatchAlarmLow-V88MV4MSDP3H
INFO: Added instance [i-0086bb04a1a0d57b9] to your environment.
INFO: Environment health has transitioned from Pending to Ok. Initialization completed 27 seconds ago and took 3 minutes.
INFO: Successfully launched environment: myapp-env
$ eb status 
Environment details for: myapp-env
Application name: myapp
Region: eu-west-2
Deployed Version: app-170629_125010
Environment ID: e-r4aeg3mdhp
Platform: arn:aws:elasticbeanstalk:eu-west-2::platform/Puma with Ruby 2.3 running on 64bit Amazon Linux/2.4.1
Tier: WebServer-Standard
CNAME: myapp-env.itykuuzig2.eu-west-2.elasticbeanstalk.com
Updated: 2017-06-29 11:54:30.354000+00:00
Status: Ready
Health: Green
$ rake secret
generatesalongkey
$ eb setenv SECRET_KEY_BASE=generatesalongkey

Setting up PostgreSQL with Rails on your Instance


packages:
yum:
postgresql93-devel: []
$ git add .
$ git commit -m 'adding .config for postgres setup'
$ git push origin master
$ eb deploy
$ eb open

Software Developer https://jameshamann.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store