anchor.diff:  == Multi-Tier Deployments
   
   
  -For production deployments, allocating a separate RDS database instance and allowing multiple nodes to handle traffic behind a load balancer is the recommended option. In this model, we rely on AWS ELB to correctly spread the traffic among the various nodes, and also to route traffic to either  Kill Server or KAUI based on the incoming port. Note that such deployment option requires a bit more setup and so we also provide an (easier) way to deploy using https://docs.killbill.io/latest//aws-cf.html[CloudFormation templates]. However, the benefits of this option is that it provides more control in the deployment.
  +For production deployments, we recommend a *multi-tier* configuration with two or more EC2 instances and a separate database instance using the `Amazon Relational Database Service (RDS)`. In place of `nginx`, this configuration would rely on an AWS `Elastic Load Balancer (ELB)` to correctly spread the traffic among the various nodes, and also to route traffic to either  Kill Server or KAUI based on the incoming port. This deployment option requires a bit more setup, so we also provide an (easier) way to deploy using https://docs.killbill.io/latest//aws-cf.html[CloudFormation templates]. However, the multi-tier option provides more control over the deployment.
  +
  +The diagram below illustrates the multitier configuration. This section will explain how to setup this option.
   
   image:https://github.com/killbill/killbill-docs/raw/v3/userguide/assets/aws/multi-tier-ami_deployment.png[align=center]
   
  -
  -The steps are the following:
  -
  -**Notes:** We are waiting for AWS Marketplace team to approve our `Multi-Tier` AMI, and will update this doc with the link when it is ready.
  -
  -[1] Setup of the RDS instance
  -
  -You can chose any options that are `mysql` or `postgresql` compatible. Using Aurora (mysql) is probably a good choice.
  -Make sure to correctly setup your VPC, and subnets.
  -
  -[2] Start the instances
  -
  -The steps are similar to the one described for the section `Single-Tier Deployment` above, but in addition, when starting the instance, you will need to specify the properties associated with your RDS instance. In order to make it easy, we have created a `User data` template script, which will need to be edited to specify the real values:
  +[1] Setup the Database
  +
  +The first step is to setup the RDS instance. This process begins with the RDS dashboard, which is distinct from the EC2 dashboard. Open the dashboard, select `Databases` from the left menu, and click the red button at the top right that reads `Create Database`:
  +
  +image:https://github.com/killbill/killbill-docs/raw/v3/userguide/assets/aws/create-database.png[align=center]
  +
  +You will be taken to the `Create Database` page. The first choice you will have is between `Standard Create`, which allows you to set a full range of configuration parametera, or `Easy Create`, which sets most of these parameters to defaults. We recommend `Easy Create` in most cases.
  +
  +image:https://github.com/killbill/killbill-docs/raw/v3/userguide/assets/aws/standard-or-easy.png[align=center]
  +
  +The next section offers you a choice of several database types. Kill Bill can work with any database type that is `mysql` or `postgres` compatible. For robust production use, Amazon Aurora is probably a good choice. Here we will illustrate the simpler steps setting up a MariaDB database.
  +
  +image:https://github.com/killbill/killbill-docs/raw/v3/userguide/assets/aws/database-types.png[align=center]
  +
  +The next choice determines the instance size. We suggest the `Production` option as this will provide the most robust configuration.
  +
  +image:https://github.com/killbill/killbill-docs/raw/v3/userguide/assets/aws/instance-sizes.png[align=center]
  +
  +The last section asks you to:
  +
  +1. Specify a name for your database
  +2. Give a username for the administrative account (we suggest that you do *not* use the default name
  +3. Provide a password for the administrative acount (we suggest you let AWS generate one for you)
  +
  +image:https://github.com/killbill/killbill-docs/raw/v3/userguide/assets/aws/names-and-password.png[align=center]
  +
  +WHen the password is setup and confirmed, click `Create Database` in the lower right corner. You will return to the main Databases screen, which should now look like this:
  +
  +image:https://github.com/killbill/killbill-docs/raw/v3/userguide/assets/aws/database-starting.png[align=center]
  +
  +This display shows that your database is starting. After a few minutes, the status will change to `Available` (You may need to reload the page to see this). At this time you can click on the database name to get more information, including the full name of the instance.
  +
  +On the page that appears you should see a panel named `Connectivity and Security`. THe left side of this panel shows the full name of the endpoint, which you will need shortly, and the port number, which is normally 3306.
  +
  +image:https://github.com/killbill/killbill-docs/raw/v3/userguide/assets/aws/connectivity-and-security.png[align=center]
  +
  +[2] Edit the configuration script
  +
  +To set up the EC2 instances you will need to provide them with information needed to connect to the databases. We provide a brief configuration script to simplify this process. The template for this script is as follows:
  +
   
   ```
   #!/bin/bash
  
positive.code: 
  cat <<_EOF > $KB_PROPS
  #
  # EDIT FOLLOWING KB PROPERTIES BELOW AS NEEDED
  #
  org.killbill.dontexist=foo
  _EOF
  
  su -l -c "cd /var/lib/tomcat/bin && /var/lib/tomcat/bin/updateProperties.sh $DB_PROPS $KB_PROPS" tomcat
  ```
  
  Specifying such user data script in the AWS UI is shown below:
  
  image:https://github.com/killbill/killbill-docs/raw/v3/userguide/assets/aws/userdata.png[align=center]
  
  
  Make sure that the security group for the EC2 instance also includes the security group for the RDS instance to ensure your EC2 instances can connect to RDS.
  
  [3] Install database schema
  
  In order to install the database schema, you will need to `ssh` to one EC2 instance using your private key -- make sure you have alowed incoming SSH traffic on port `22` in your security group.
  
  ```
  # SSH as ubuntu user
  
negative.code: > mysql -h db-instance-1.cah16olm8gkg.us-east-1.rds.amazonaws.com -u admin -p5Xn21rhxr3Km4jC7N7ol kaui < kaui.ddl
  ```
  
  [5] Stop and Restart the KillBill Service
  
  ```
  > sudo service killbill stop
  