Developing in Rails on AWS Cloud9

I used Cloud9 a few years back for a Rails project while they were still an independent startup and it was all pretty seamless to get up and running on their cloud IDE.

Fast forward a few years and they have been acquired by Amazon and integrated into the AWS suite of services. However, upon logging into my AWS and trying out AWS Cloud9, I realised that it’s not as straightforward getting a Rails dev environment set up as before.

After much Googling, I finally got everything set up so I decided to compile this handy guide for future reference.

Setup Cloud9 on AWS

To get started, you need to have an AWS account. Sign in to your AWS console at https://console.aws.amazon.com/.

Configure IAM Groups and Users

Whilst you can use your AWS root account to create Cloud9 environments, it is highly recommended that you create IAM users with appropriate Cloud9 access rights. This prevents unrestricted access to other services within your AWS account and allows you to manage access for other Cloud9 users in your team.

Create Groups

We will create two IAM Groups, Cloud9Admins and Cloud9Users:

  • Cloud9Admins have permission to create new Cloud9 environments. This group should be restricted to trusted users for administering the platform.
  • Cloud9Users have permission to use existing Cloud9 environments. Regular team members should be assigned to the Cloud9Users group.
  1. From the AWS console open IAM from the Services menu.
  2. In the IAM console’s navigation pane, choose Groups.
  3. Choose Create New Group.
  4. On the Set Group Name page, for Group Name, enter either Cloud9Admins OR Cloud9Users
  5. Choose Next Step.
  6. On the Attach Policy page, search for the filter term: cloud9

7. Select either AWSCloud9Administrator (if creating the Cloud9Admins group) OR AWSCloud9User (if creating the Cloud9Users group)

8. Choose Next Step, then Create Group.

9. Repeat steps 1–8 until both Cloud9Admins and Cloud9Users groups are created.

Create Users and Assign to Groups

  1. In the IAM navigation pane, choose Users.
  2. Choose Add user.
  3. On the Details page, for User name, type a name for the new user.
  4. Select Programmatic access and AWS Management Console access.
  5. Choose a password method for the user to suit your requirements.
  6. Choose Next: Permissions.
  7. On the Permissions page, leave the default choice of Add users to group.
  8. In the list of groups, select the box next to the group you want to add the user to. Either Cloud9Admins OR Cloud9Users
  9. Choose Next: Review.
  10. On the Review page, choose Create user
  11. Repeat steps 1–10 to create additional users or admins.

Create a Cloud9 Environment

Note: Cloud9 uses an AWS EC2 instance to host your files and services. In this example we will use a t2.micro instance which may be eligible for free-tier pricing. However, you could be charged EC2 hosting fees for Cloud9 past this point. Please ensure you are aware of the free-tier and other usage fees for your environment before continuing.

  1. Sign-in to your AWS console as a Cloud9Admins user.
  2. Open Cloud9 from the Services menu.
  3. Choose Create environment.
  4. From the Name environment page, enter a Name for your environment
  5. From the Configure settings page, select both Create a new instance for environment (EC2) and t2.micro (1GiB RAM + 1 vCPU)
  6. Choose Next step.
  7. Choose Create environment

Configure Postgres

Install Postgres via Yum

sudo yum install postgresql96 postgresql96-server postgresql96-devel postgresql96-contrib postgresql96-docs

Run postgres service init

sudo service postgresql96 initdb

Edit postgres conf to connect via localhost:5432

sudo vim /var/lib/pgsql96/data/postgresql.conf

Uncomment #listen_addresses and #port

listen_addresses = 'localhost'

and

port = 5432

Update pg_hba.conf file for ec2-user auth

sudo vim /var/lib/pgsql9/data/pg_hba.conf

Edit conf to be:

# TYPE  DATABASE        USER            ADDRESS               METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all ec2-user 127.0.0.1/0 trust
# IPv6 local connections:
host all all ::1/128 md5

Start / Restart postgres server

sudo service postgresql96 start

or

sudo service postgresql96 restart

Login as Postgres User and Change Password / Add ec2-user

sudo su - postgres # login as postgres userpsql -U postgres # login to postgres db as postgres user

Change Password:

ALTER USER postgres WITH PASSWORD 'YOUR_PASSWORD';

Add ec2-user :

CREATE USER "ec2-user" SUPERUSER;
ALTER USER "ec2-user" WITH PASSWORD 'YOUR_PASSWORD';

Exit postgres:

postgres=# \q

Logout of postgres user account:

exit

Set up Rails app

Clone or create a new application then run

bundle install
rails db:setup

Configure a Run Configuration

AWS Cloud9 has built-in tools for running a Rails server for previewing your app in a web browser. Configure as follows:

  1. Right-click the Run menu, then choose New Run Configuration
  2. From the Terminal area (Fig 7), in the Run Config Name field, enter <appname>
  3. From the Terminal area, in the Command field, enter rails s -b 0.0.0.0
  4. From the Terminal area, choose CWD, then choose the <appname> folder from the list.
  5. Click Run.

Previewing in your Browser

To view the output of your rails server in a browser, Cloud9 provides an automatically generated private URL that is connected to your server:

  1. From the main menu, choose Preview > Preview Running Application
  2. In the Browser window that appears, click Pop Out Into New Window
  3. The application should now be running in your browser!

--

--

--

Co-founder of Excide. Learning to use tech for good. Also a Christian, coder, photographer & avgeek.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How to get Purchase Order version specific tax amount using X++ in Dynamics 365 Finance & Operation

How to create a Strava route without a subscription

Obtain Silver Prices From MEX Nepal Using An API

SQL Azure for Access Developers

Css Solved Mcqs 2020 & 2021 Past Papers

CSSMCQs Android APK app download image showing

Introduction to AWS — Amazon Web Services | සිංහලෙන්

What APIs can teach you about effective communication

Best Features in Python 3.10

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
H. S. Chin

H. S. Chin

Co-founder of Excide. Learning to use tech for good. Also a Christian, coder, photographer & avgeek.

More from Medium

Module 3 — Ruby

Ruby + Dynamodb in Local environment

Monday, Monday — The show must go on

A ruby rookie’s tips and tricks for the newcomers | Part 1