# Deploying RhoConnect with High Availability on Amazon Web Services
This tutorial will guide you through setting up a Redis stack and a RhoConnect application stack in the Amazon Web Service (AWS) cloud.
The RhoConnect application stack is scalable; it uses load balancing to automatically distribute and balance the incoming application traffic among all the instances you are running. You will set the maximum number of instances that the load balancer can create for your RhoConnect application.
## Logging onto the Amazon Web Service
Go to the [Amazon Web Service (AWS) Console](http://aws.amazon.com/console/) and click on the Sign in to the AWS Console button. You can sign into an existing AWS account, or create a new one.
Or you can open the URL for your account directly if you have the account number:
:::term
https://.signin.aws.amazon.com/console
Enter your User Name and Password for your AWS account, then click the Sign in button.
## Creating a Custom RhoConnect Image
In the AWS Management Console, change the Region to US West (N. California).
**NOTE:** The stacks created in this document only work in the N. California region.
We provide a few public preconfigured images that contains a blank RhoConnect app for `Us West N. California` region:
* `ami-cbc59e8e` (RhoConnect-3.1.2 with Nginx and phusion passenger)
* `ami-0dfca748` (RhoConnect-3.2.0 with Nginx and cluster of thin servers)
### Launching an Instance
To create your own RhoConnect Image, launch an EC2 Image:
Click the EC2 tab, click EC2 Dashboard, then click the Launch Instance button.
Click the Launch Classic Wizard radio button. Click Continue.
### Requesting the Instance
In the Choose an AMI section, click the Community AMIs tab.
Then paste in the AMI ID, i. e. `ami-cbc59e8e`. When the preconfigured RhoConnect AMI appears, click Select.
In the Instance Details section, select the Instance Type (such as Large).
In the Instance Details section, Advanced Instance Options screen, change nothing. Click Continue.
In the Instance Details section, Add Tags screen, enter a name for your custom RhoConnect EC2 instance in the Value Column of the Name key, then click Continue.
In the Create Key Pair section, select your existing key pair or create a new keypair.
### Requesting the Instance - Configuring the Firewall
In the Configure Firewall section, click the Create New Security Group radio button.
Click the Add Rule button to add each port.
* Add port 22 for SSH.
* Add port 80 for HTTP.
* Add port 6379 for redis.
**NOTE: You may use a preexisting security group if it has ports 22, 80, and 6379 open. **
Enter a firewall name and a group description, then click Continue.
Make sure all the instance information is correct as shown on the Review page and then click Launch.
In the window titled "Launch Instance Wizard", click Close and wait for your instance to be Running.
### Customizing the Instance
In the EC2 tab, click on Instances.
For Viewing, select Running Instances. Select your newly created RhoConnect instance and scroll down to see Private DNS in the lower section of the My Instances screen.
You will need:
* your keypair (the .pem file AWS gives you when the keypair is created)
* the public DNS name of the Instance, which you will see as the public DNS name in the running instance. For Example: `ec2-184-72-16-39.us-west-1.compute.amazonaws.com`.
* the username: `ec2-user`
From the command line, use ssh to login to the running instance, using the keypair, DNS name, and user name. For example:
:::term
$ ssh -i ~/.ssh/devkey.pem ec2-user@ec2-50-18-229-26.us-west-1.compute.amazonaws.com
Replace the blank 'rhoapp' application in the /opt/nginx/html folder with your app, and set its owner as 'nginx' user.
:::term
$ cd /opt/nginx/html
# ... copy your application here under name 'rhoapp'
$ sudo chown -R nginx:nginx rhoapp
You can test the application.
:::term
$ sudo /etc/init.d/redis start
$ sudo /etc/init.d/nginx start
**NOTE: If your instance based on `ami-0dfca748` (RhoConnect-3.2.0) image, then you need to do one more step:**
:::term
$ sudo /etc/init.d/thin start
If everything is configured properly, then you can login to the RhoConnect web console in your browser by using the instance's public DNS name as the URL in your browser. When you are done, you can stop the application.
:::term
$ sudo /etc/init.d/nginx stop
$ sudo /etc/init.d/redis stop
**NOTE: Do not forget also stop cluster of thin servers if your instance based on `ami-0dfca748` (RhoConnect-3.2.0):**
:::term
$ sudo /etc/init.d/thin stop
## Create the Image
In the EC2 tab, right-click the RhoConnect instance and select Create Image (EBS AMI).
In the Create Image window, enter the image name and description for your custom image. Then click Create This Image.
In the Create Image window showing that the request is received, click on "View pending image: ami-XXXXXXXX to go to your Amazon Machine Image.
Copy the AMI number; you will use it when you create the scaleable RhoConnect stack.
## Creating the Scalable RhoConnect Stack
Click the Cloud Formation tab.
Ensure that the Region selected is US West (N. California) and Click the Create New Stack button.
### Create Stack - Select Template
In the Select Template section, you must select the template file for your redis stack. This is the template to run the AMI image with the Redis server.
First, enter the name that you want for your stack into the Stack Name field.
Now get the template by either providing the URL for the template file, or by uploading the template file.
#### Providing the URL for the Template File
Click the Provide a Template URL radio button.
If your custom image based on `ami-cbc59e8e`(RhoConnect-3.1.2) image, then copy the following URL and paste it into the text field below the Provide a Template URL radio button:
`https://s3-us-west-1.amazonaws.com/rhoconnect-ca-deploy/rhoconnect_template.txt`
If your custom image based on `ami-0dfca748` (RhoConnect-3.2.0), then use this URL:
`https://s3-us-west-1.amazonaws.com/rhoconnect-ca-deploy/rhoconnect_template-3.2.txt`
#### Uploading the Template File
Click the Upload a Template File radio button.
In another browser window, go to [https://s3-us-west-1.amazonaws.com/rhoconnect-ca-deploy/rhoconnect_template.txt](https://s3-us-west-1.amazonaws.com/rhoconnect-ca-deploy/rhoconnect_template.txt)
if your custom image based on `ami-cbc59e8e` (RhoConnect-3.1.2).
If your custom image based on `ami-0dfca748` (RhoConnect-3.2.0), then to go
[https://s3-us-west-1.amazonaws.com/rhoconnect-ca-deploy/rhoconnect_template-3.2.txt](https://s3-us-west-1.amazonaws.com/rhoconnect-ca-deploy/rhoconnect_template-3.2.txt).
Save that text file to your computer.
Click the Choose File button, and navigate to and select your template file.
Click Continue.
### Create Stack - Specify Parameters
In the Create Stack: Specify Parameters window:
* Enter the AMI image number that you saved earlier.
* Enter the maximum number of RhoConnect application servers that you want to run in your stack. Default = 2.
* Enter the name for your existing EC2 KeyPair to enable SSH access to the stack instances.
Click Continue.
### Create Stack - Review
Click Continue to see a window entitled \"Create Stack\" showing that the stack is being created.
Click Close.
## Checking the Status
In the AWS Management Console, Cloud Formation tab, click the checkbox for your stack. To see the progress of the creation of your stack, click the Refresh button; the status should become CREATE_COMPLETE soon.
To see the progress of the components in your stack, you can click the Events tab. You can click the refresh button to see the progress.
## Using the RhoConnect Application URL
In the AWS Management Console, Cloud Formation tab, click the Outputs tab. You will see a list of the Stack Outputs.
At the top of the output list is the URL of the RhoConnect application. You can click on it to see the RhoConnect Console for the running RhoConnect server.
To use this scaleable RhoConnect server in your Rhodes application, copy the URL for the RhoConnect application into the rhoconfig.txt file in your Rhodes application as the syncserver variable. For example:
:::term
syncserver = http://rhoconnec-RhoLoadB-OX64XR1IKNT2-1364705573.us-west-1.elb.amazonaws.com
## Deleting the Stack
You are charged for the stack that you have created, by the hour. When you no longer want to use the stack, you can delete it by right-clicking on the stack name in the AWS Management Console, Cloud Formation tab, and clicking Delete Stack.