Getting Started with Cloud Foundry

Get AWS credentials

In order to use Cloud Foundry, you need to provide your Amazon Web Services credentials along with a EC2 key pair.

Signing Up

The first step is to sign up for Amazon Web Services. To begin the process go to AWS home page and click this button:

Get Started

Follow the instructions and then signup for the Amazon EC2 webservice.

Once you have done that you then need to note your access key id and secret key id - you will need to give them to Cloud Foundry. You can find those out by going to the 'access identifiers' part of the AWS website.

Generating a key pair

Amazon EC2 requires a key pair (not to be confused with X509 certificate associated with your AWS account) to allow secure access. The key pair is used by Cloud Foundry to launch instances and to SSH into them. Cloud Foundry can generate such key pairs for you automatically, if you have not already generated EC2 key pairs reviously. There are two places where you can automatically generate the key pairs in Cloud Foundry:

  1. The AWS Credentials Wizard that runs the first time you log in.
  2. The Generate Key Pairs button on the SETTINGS tab.

Now that you have your AWs credentials and your key pair you are ready to use Cloud Foundry to deploy applications.


Generating Key Pairs Manually

Optionally, you can create a EC2 key pair manually by using one of the AWS tools: command line tools, ElasticFox plugin or the rather nice AWS console. Under the covers these tools make an AWS request to create the key pair.

Create Key Pair

There are three steps:

  1. Select Key Pair
  2. Click Create Key Pair
  3. Enter the name of the Key Pair you want to create - you choose the name

The console will then create the key pair and prompt you to save the private key.

Create Key Pair

Later on you will need to give Cloud Foundry the key pair name and private key file. Cloud Foundry specifies the key pair name in the AWS request that launches the instances and uses the private key file to authenticate when connecting to the instance with ssh. You will also need the key pair if you want to ssh into your instances. Make sure you save the key pair in safe place.


Running applications on Cloud Foundry

Cloud Foundry deploys your application on the following software stack:

  • Apache 2.2.3
  • SpringSource tc Server (Tomcat 6) or Tomcat 5.5.23
  • MySQL 5.0.45

You can either run Apache/Container/MySQL on a single Amazon EC2 instance (a.k.a SingleInstanceTopology) or run each server on its EC2 instance (a.k.a. MultipleInstancesTopology).

Accessing the database

One challenge when deploying on Amazon EC2 is that the IP address of the MySQL server is assigned dynamically. There are two different ways the application can access the MySQL server.

Using a hardwired hostname

One option is to hardwire the hostname of the MySQL server into the application. If your application is always going to be deployed using a SingleInstanceTopology then you can simply use localhost to access the MySQL server. However, a more flexible approach is to use 'dbmaster' as the hostname.Cloud Foundry ensures that 'dbmaster' always resolves to the IP address of the MySQL server.

Using a system property

The second and more flexible approach is to launch the application with system property that specifies the MySQL server hostname. For example, this JVM option "-DdbHostName=${databasePrivateDnsName}" sets the the system property'dbHostName' to the MySQL server's host name.

A Spring/Java application can then use a PropertyPlaceholderConfigurer bean to substitute this value into the database url, e.g. jdbc:mysql://${dbHostName}:3306/.

Similarly, a Grails application can use something like this in the grails-app/conf/DataSource.groovy:


    environments {
      development {
         dataSource {
             dbCreate = "create-drop" // one of 'create', 'create-drop','update'
             url = "jdbc:mysql://${System.getProperty("dbHostName", "localhost")}/..."
         }
      }
    }
                    

Other issues and limitations

  • Amazon EC2 does not support multicast