This application will demonstrate many of the concepts introduced in this class.
Git tags are used to indicate various points of progression.
Project Name: Demo
Team Members:
Bryce Boe (@bboe)
- Preparing this Rails Application for Elastic Beanstalk
- Preparing Your Application for Elastic Beanstalk
- Creating Elastic Beanstalk Deployments
- Modifying Running Deployments
I've set up a linux server on Amazon EC2 that you can utilize for easy interaction with elasticbeanstalk. (Alternatively, you could set up the CLI for elastic beanstalk on your local machine.)
-
SSH into that server using the provided TEAMNAME.pem file:
ssh -i TEAMNAME.pem [email protected]
-
On the EC2 instance you just ssh'd into, take note of your aws-access-id and aws-secret-key which can be found via:
cat ~/TEAMNAME_key.txt
WARNING: Never commit these credentials into your repository, or put them anywhere else that they might be made public.
-
From the home directory, clone this repository:
git clone https://github.com/scalableinternetservices/demo.git
-
Change into the project directory, and initialize elasticbeanstalk:
cd demo eb init
-
Use the us-west-2 region (default).
-
Provide your aws-access-id. (if prompted)
-
Provide your aws-secret-key. (if prompted)
-
Create a new application (default) for your team if no such application already exists.
- Use your team name as your application's name.
-
Indicate that you are using ruby.
-
For now, choose Ruby 2.5 (Puma) as your platform (default). You can experiment with passenger later.
-
Do not continue with CodeCommit (default).
-
Indicate that you do want to set up SSH for your instances (default).
- Choose the keypair that matches your team's name.
-
To test this configuration, skip ahead to section "Creating Elastic Beanstalk Deployments", wherein you will deploy this demo project to Elastic Beanstalk.
Use similar steps as above to initialize eb
for your own project's
repository. Note that eb init
must be run from the top most directory of your
repository.
Next you need to make some changes to your application in order to configure it to work well with elasticbeanstalk.
-
Ignore most of the elastic beanstalk related files.
- Make a similar change to
.gitignore
as added here: https://github.com/scalableinternetservices/demo/commit/9c027be29d125e5ad69bfc5adf7c91b4dff39be3#diff-a084b794bc0759e7a6b77810e01874f2
- Make a similar change to
-
Update your Gemfile to use the
pg
gem in production, andsqlite3
in development.-
Make a similar change to
Gemfile
as added here (do not manually updateGemfile.lock
): https://github.com/scalableinternetservices/demo/commit/9c027be29d125e5ad69bfc5adf7c91b4dff39be3#diff-8b7db4d5cc4b8f6dc8feb7030baa2478 -
Run
bundle install --without-production
to update yourGemfile.lock
.
-
-
Configure your production database settings to use postgresql and to fetch the right settings from the environment provided by elastic beanstalk.
- Make similar changes as added here: https://github.com/scalableinternetservices/demo/commit/9c027be29d125e5ad69bfc5adf7c91b4dff39be3#diff-e31bdf70b15c8f84344c332efe06900d
Once you have prepared either the demo application, or your application, you can make various deployments of said application.
Use the following command when you are simply testing out changes, or demoing because this will create a deployment that operates with the cheapest cost.
eb create -db.engine postgres -db.i db.t2.micro -db.user u --envvars SECRET_KEY_BASE=RANDOM_SECRET --single DEPLOYMENT-NAME
Replace DEPLOYMENT-NAME
with a unique name for your
deployment. Consider teamname-yourname
.
Replace RANDOM_SECRET
with some semi-random large string of
alphanumeric characters. Note, for real sites you want this to be
really random as your cookies are signed/encrypted using a key derived
from this string.
When you are ready to run tsung tests, use a form of the following command to specify the database instance type, and application server instance type.
eb create -db.engine postgres -db.i DB_INSTANCE_TYPE -db.user u --envvars SECRET_KEY_BASE=RANDOM_SECRET -i INSTANCE_TYPE DEPLOYMENT_NAME
Replace DB_INSTANCE_TYPE
with one of:
- ($0.178) db.m5.large 2 vCPU / 8 GiB
- ($0.356) db.m5.xlarge 4 vCPU / 16 GiB
- ($0.712) db.m5.2xlarge 8 vCPU / 32 GiB
- ($1.424) db.m5.4xlarge 16 vCPU / 64 GiB
- ($0.250) db.r4.large 2 vCPU / 15.25 GiB
- ($0.500) db.r4.xlarge 4 vCPU / 30.5 GiB
- ($1.000) db.r4.2xlarge 8 vCPU / 61 GiB
- ($2.000) db.r4.4xlarge 16 vCPU / 122 GiB
Replace INSTANCE_TYPE
with one of:
- ($0.085) c5.large 2 vCPU / 4 GiB
- ($0.170) c5.xlarge 4 vCPU / 8 GiB
- ($0.340) c5.2xlarge 8 vCPU / 16 GiB
- ($0.680) c5.4xlarge 16 vCPU / 32 GiB
- ($1.530) c5.9xlarge 36 vCPU / 72 GiB
- ($0.096) m5.large 2 vCPU / 8 GiB
- ($0.192) m5.xlarge 4 vCPU / 16 GiB
- ($0.384) m5.2xlarge 8 vCPU / 32 GiB
- ($0.768) m5.4xlarge 16 vCPU / 64 GiB
See the following for differences between the instance types:
To manage your deployments, log in to the AWS web console and go to the "configuration" tab:
https://console.aws.amazon.com/console/home
- Account ID or alias: bboe-ucsb
- IAM user name and Password: See the file
TEAMNAME.txt
in your team's home folder of the EC2 instance atec2.cs291.com
.
Vertically scale by changing the instance type [Ref].
Horizontally scale by adjusting the minimum and maximum number of instances [Ref].
Note: set the minimum and maximum instance count to the same value to keep the instance number fixed throughout the duration of your test. Verify all instances are available before running any tests.
Run eb terminate
to terminate the active deployment. Alternatively
run eb terminate DEPLAYMENT_NAME
to terminate a different
deployment.
To update the application source code perform the following tasks:
-
Run
git pull
to update the copy of the repository. -
(Optional) Check out a branch if you intend to work with a branch. Ensure the local copy is up-to-date.
-
Run
eb list
to see which deployment is currently active (it will have a*
next to it). -
(If needed) Run
eb use DEPLOYMENT_NAME
to change the active deployment. -
Run
eb deploy
to update the active deployment.