Recently we went through the process of installing a micro Cloud Foundry on a local virtual machine. We are now interested in doing the same on an Amazon EC2 instance. As far as I have been able to find, the existing instructions for using AWS set up a system with many VMs. In this post we look at a “micro” (or single-machine) Cloud Foundry setup.
To do this you need to sign up for an Amazon AWS account. Next, you need to decide where to build your Cloud Foundry instance. Amazon has data centers in eight regions, and you can pick based on geography (close to you has less network latency) and price (some are more expensive). I am close to the US (West) Oregon Region (us-west-2) and it is among the least expensive.
Next you select a base operating system for your machine. Cloud Foundry recommends 64-bit Ubuntu 10.04 LTS, so go to Ubuntu’s Amazon EC2 AMI Locator and enter ’64 lucid ebs’ in the search area (since we are going to make changes to the setup we want to be on a persistent store, hence the EBS selection). When the search list is narrowed down to one for each region, click on the link for the region you want.
This takes us to the EC2 Management Console (perhaps with a login) where you can review information about the selected AMI and click the Continue button.
For the Instance Details, change the Instance Type from ‘T1 Micro’ to ‘M1 Small’ or ‘M1 Medium’ and click Continue.
Next, give ‘CF Micro’ as ‘User Data’ and click Continue.
Do not make any changes to the Storage Device Configuration; simply click Continue.
For the Tags, give ‘CF Micro’ as the Name and click Continue.
To interact securely with the instance you need a key pair. The Wizard prompts for a name and you may enter anything (such as ‘cfMicro’) and then click ‘Create and Download your Key Pair’.
The default Security Group does not allow any outside access to the instance. Create a new Security Group, named ‘CF Micro’ with a description of ‘ping, ssh, http’, add the appropriate rules, and click Continue.
Next, click the Launch button to start the instance.
When informed that the instance is starting, click Close.
This takes us to the list of Instances on the Management Console.
When we built a micro Cloud Foundry on a local virtual machine, the IP address was assigned by Fusion and was the same from “inside” and “outside” the machine. When running an EC2 instance on AWS, the machine is behind a firewall and on an internal (private) network. While our virtual machine can be reached via a public IP address, the machine actually has a different IP address.
Optional: If we stop and start the machine the default behavior is that we are likely to get a different public address. In order to have a stable IP address for our instance, we can to allocate an Elastic IP and associated it with the running instance. (If you are only doing this once and will throw away the system, then you can skip this step.) From the EC2 Management Console, click Elastic IPs in the navigation pane on the left and then click the Allocation New Address button (instructions here).
Optional (continued): Select the new address and click the Associate Address button. In the dialog box select the running instance and click the Yes, Associate button.
Whether you have a stable IP or not, you now are almost ready to log on to our new server. Click on Instances in the navigation pane on the left and select the CF Micro instance, right click, and select the ‘Connect’ menu command.
This gives us a window with instructions on how to connect to the instance. I prefer to use SSH from Terminal.app on my MacBook Pro, so look at the instructions for the standalone SSH client.
Before you can use the command line provided (highlighted above) you need to do a little bit of setup on our local machine. Create a working directory and copy the private key downloaded earlier. Then connect to the new server (your IP address will be different).
mkdir ~/cloud/cfMicro cd ~/cloud/cfMicro mv ~/Downloads/cfMicro.pem . chmod 400 cfMicro.pem ssh -i cfMicro.pem ubuntu@54.213.201.105
Once logged in to the server, you can install Cloud Foundry using Iwasaki Yudai’s cf_nise_installer.
export IPV4=`wget -qO- http://instance-data/latest/meta-data/public-ipv4` export NISE_DOMAIN=$IPV4.xip.io export CF_RELEASE_BRANCH=release-candidate bash < <(curl -s -k -B https://raw.github.com/yudai/cf_nise_installer/${INSTALLER_BRANCH:-master}/local/bootstrap.sh)
When this finishes, you should restart your server.
sudo shutdown -r now
After a minute or so, log in to the server again using the ssh command above and start your Cloud Foundry.
(cd ~/cf_nise_installer; ./local/start_processes.sh)
Once the server is started, you can logout from the server (or open a second session on your client) and create a new application to push to your cloud. I suggest that you follow my earlier example with the following manifest.yml (change the domain to reference your server’s IP address):
--- applications: - name: env memory: 256M instances: 1 host: env domain: 54.213.204.16.xip.io path: . command: 'ruby env.rb'
Then use the Cloud Foundry command line tools to configure things and push your application (use your own IP address instead of the one shown here!).
cf target http://api.54.213.204.16.xip.io cf login --password c1oudc0w admin # okay to ignore CFoundry::InvalidRelation error in next command # (see https://github.com/cloudfoundry/cf/issues/9) cf create-space development cf target --space development cf map-domain --space development 54.213.204.16.xip.io cf push
When this finishes, you should be able to open a web browser on something like (use your own IP address) http://env.54.213.204.16.xip.io/env and see the application. Congratulations!
Leave a comment
Comments feed for this article