- Go to http://aws.amazon.com
- Click Sign up
- Follow sign up instructions
FYI You will need a credit card but it will only get charged if you use resources outside the free tier and you will need a phone number to verify your identification.
Reference: http://docs.aws.amazon.com/IAM/latest/UserGuide/Using_SettingUpUser.html
- Log in to aws console https://console.aws.amazon.com
- Go to IAM dashboard > Users
- Create New Users
- Enter user name and generate access key
- Click on user > Permissions
- Attach UserPolicy
- Add Administrator access
- Click on security credentials and set a password
- Go to IAM dashboard and note the IAM User Sign-In URL
- Sign in as your IAM user
Reference: http://docs.aws.amazon.com/cli/latest/userguide/installing.html http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html
- Install cli
aws configureusing your IAM credentials and us-east-1 as default region- Test
aws ec2 describe-instances
- Go to EC2 in the AWS Console
- Click Launch Instance
- Select Ubuntu
- Choose t2.micro (free tier)
- Skip through next two screens to Step 5: Tag Instance
- Give your instance a name, Click next
- Create a new Security Group, name it blog, and keep the default SSH from anywhere rule for now
- This will show a warning about SSH being accessible to the world. This is fine for now but can be fixed if you choose "My IP" instead of "Anywhere".
- Click Next and Launch
- It will ask you about a KeyPair, this time create a new one. It will have you download the private key to your computer. You will need this to access the instance later.
At this point your instance will be created. You will need to wait for it to be in the running state before you can access it.
- Go to the EC2 Instances page in the console and get the public DNS of the instance you launched.
- Use the public DNS and the key pair you created the instance with to ssh into the instance.
- For example:
ssh -i si.pem ubuntu@ec2-54-210-57-41.compute-1.amazonaws.com - Note: the private key file can only be readable by you. Run
chmod 400 si.pem.
- For example:
- Update the package manager:
sudo apt-get update - Install git:
sudo apt-get install git - Clone this repo:
git clone https://github.com/mtrahan/fuzzy-octo-computing-machine.git - Change directories to the repo:
cd fuzzy-octo-computing-machine - Run the setup-instances script to install all necessary ruby dependencies:
sudo ./setup-instance.sh - Change directories to the ruby app directory:
cd blog - Run
bundle install - Setup the local database:
bin/rake db:migrate - Start the App:
bin/rails server - Go to your browser and hit the public DNS of the instance at port 3000. Example: http://ec2-54-210-57-41.compute-1.amazonaws.com:3000
- This will not work because the security group needs to have a rule added to open port 3000.
- Go to EC2 -> Security Groups
- Click on the blog security group and add an Incoming rule to open a TCP port 3000 to all IPs 0.0.0.0/0
- This will not work because the security group needs to have a rule added to open port 3000.
- Go to RDS in AWS Console.
- Click Launch a DB Instance
- Choose PostgreSQL
- Pick No, this instance is intended for use outside of production or under the RDS Free Usage Tier
- Select the following:
- DB Instance Class: db.t2.micro
- Multi-AZ Deployment: No
- Allocated Storage: 5
- DB Instance Identifier: blog
- Set username and password. Remember these.
- On the next screen select the following:
- Publicly Accessible: No
- VPC Security Group(s): blog (this is the same security group you created with your first instance)
- Database Name: blog
- Leave the rest with their default values
- Launch!
- Once the database is up and running, we need to open up the security group so our instances can call it.
- Go to EC2 -> Security Groups
- Click on blog security group
- Add rule for TCP for port 5432 but this time add the blog security group as the source. This only allows instances in that security group to make calls to this port.
- Get the endpoint for you DB from the RDS page. It will look something like this: blog.dw1zpjs4fexx.us-east-1.rds.amazonaws.com:5432
- Back on your EC2 instance with your app running on it, add the database configuration to connect to your RDS instance.
- In config/database.yaml, under production add
url: postgresql://blog:blogpassword@blog.cw1zpjs4feww.us-east-1.rds.amazonaws.com:5432/blogbut with your user/password and your connection string.
- In config/database.yaml, under production add
- Make sure
gem 'pg'is in your GemFile and runbundle install again export RAILS_ENV=productionexport SECRET_KEY_BASE=`bin/rake secret`- run
bin/rake db:migrate bin/rails server
- Go to EC2 Instances page
- Select instance
- Click Actions -> Create Image
- Go to EC2 AMI page to see status of image
- Clone git repo to local computer:
git clone https://github.com/mtrahan/fuzzy-octo-computing-machine.git - Go to CloudFormation tab and click Create New Stack
- Add a Name
- Upload template to Amazon S3, choose the file instance-only.template from the repo you just cloned
- Click Next
- Fill in the AmiId and the KeyPair name. The AmiId will be the ID for the image created in the last section and the KeyPair name will be the one you created when you launched your first instance.
- Add a Name tag to your instances.
- Launch stack
When the instance comes up, you will have to ssh on the instance and manually start the app by setting the RAILS_ENV and the SECRET_KEY_BASE then running bin/rails server.
Same as Launch New Image using Image and CloudFormation but instead use the instance-userdata.template
Same as Launch New Image using Image and CloudFormation but instead use the elb-asg.template