Scala in AppFog

The PaaS AppFog has a great advantage in being able to deploy to several cloud providers at once. It is versatile in the range of languages it will support, and, to prove the point, Shammer shows how a Scala application can be deployed via the command-line tool

In this article we will discuss how to deploy a standalone Scala application in AppFog.

AppFog is a Platform as a Service (PaaS) that supports multiple languages as well as multiple clouds. It was built on top of open source PaaS Cloud Foundry and can support any language supported by Cloud Foundry, such as PHP, Java, Scala, and so on. AppFog lets you use your language of choice as well as the public cloud infrastructure. When you deploy an application, you can also select the cloud provider – Amazon, Microsoft, Rackspace, and more. One major advantage of multi-cloud support is that you can deploy an application in multiple clouds, so if one service goes down, you can easily switch to another provider.

Many sample applications (Jumpstarts) are listed in the AppFog dashboard which makes launching new applications very easy. Unfortunately no Scala applications are listed in here. So, to launch our Scala application we’ll  use af command-line tool.

 Using af command-line tool

AppFog provides a command-line tool for creating and managing your application.  It’s a ruby shell application which you can install using gem. So for installing af, you should have Ruby and RubyGems installed in your machine. To install af:

There are number of commands available with this tool, for creating the application, start/stop the application and so on. We will see them as we go on. To use af you must have an AppFog account, so create one if you don’t already have it. Then you should log in from the command-line before creating the application.

Once you have logged in successfully, you can start the application in AppFog. Before creating the application in AppFog, we need to setup it in our local machine.

Setting up the project

For demonstration purpose I’ve forked a sample Scala application from Cloud Foundry that will test palindrome, which is hosted in Github. In this application we are using Unfiltered, a library for servicing HTTP requests in Scala. We are using sbt (Simple Build Tool) with the sbt-package-dist plugin for building and packaging the application. To get started, clone the sample application from Github to your local machine.

Step inside scala-unfilter folder after cloning source code. You will see the Scala source files, sbt project folder and build file (build.sbt). scala.sbt contains build definitions such as the application name, version, and dependencies.

In the first two lines we are including the settings for sbt-package-dist. packageDistZipName is the name of package file that will be created by this plugin. Remember that the blank line between statements in build.sbt is actually required by sbt.

You can test the application locally by running sbt.

It will resolve all dependencies, compile, and automatically launch the application in the browser. Next we need to package the application for deploying in AppFog.

This will package the application into a zipped file named and save in app-base/dist/scala-unfilter-0.1.0/. This file contains all the jar files and libraries required by our application.

Deploying the application

When we deploy an application, we are basically uploading the package file to AppFog server. af push is the command for creating as well as deploying the application for first time.

The above steps will upload and start our application in AppFog. When the --path parameter is omitted, it will deploy from the current directory. Here we’ve given the path to zip file to be uploaded. Next it will ask for the application name, which we given as scala-unfilter. Then af will detect the type of application we are deploying. For example, if it is a PHP application, it will auto-detect and will ask us to confirm that. In this case, we are deploying a packaged application. So af detected it as a stand alone application and thus we are asked to select the runtime environment. For running Scala applications we need Java runtime environment.

We need to use the Start command to run the application. Once the application is deployed, AppFog will unzip the file and place it in the base folder and will try to run the application using java $JAVA_OPTS -jar scala-unfilter-0.1.0/scala-unfilter_2.9.1-0.1.0.jar command in AppFog. Next you need to choose an AppFog URL, memory reservation, and number of instance for your application. Here we’ve accepted default values for them. Then you can bind any new or existing services your application needs (like databases). We have skipped that step here.

Next you will be asked whether you want to locally save the application configuration. af will write the application’s configuration to a file named manifest.yml and store it in the application root. manifest.yml will have all the necessary information about the application like its name, URL, start command, etc. This will make further deployments easier as af will read values from this configuration file. You can directly write the configuration file for deploying application once you are familiarized with the command-line tool.

Once you have successfully followed the above steps, af will create the application in AppFog. Then it will upload packaged application and try to start using the start command we have given. If there are no other issues, you will have a running Scala application in AppFog, which you can access in the given URL.

Modifying and updating application

You don’t need to follow the above steps when you want to update the application after making modifications. Once you have finished the modifications, test it locally and make sure it is working fine. Then package application using sbt package-dist and issue the command given below from application directory.

Cool, we have successfully updated our changes in AppFog. When we update the application AppFog will completely remove old files replace them with new one. So be careful when storing static contents like images in AppFog.


AppFog is a promising multi-language, multi-cloud PaaS. Built on top of Cloud Foundry, it supports many popular languages like PHP, Java, Ruby, etc. As a Jvm-based language, we can also run Scala applications in AppFog. In this article we’ve familiarized with using af command-line tool and deploying a standalone Scala application in AppFog. This is just the beginning; you may face many issues as you add different features to the application. Feel free to post a comment if you are facing any issues. I will try my level best to answer any questions.

How you log in to Simple Talk has changed

We now use Redgate ID (RGID). If you already have an RGID, we’ll try to match it to your account. If not, we’ll create one for you and connect it.

This won’t sign you up to anything or add you to any mailing lists. You can see our full privacy policy here.


Simple Talk now uses Redgate ID

If you already have a Redgate ID (RGID), sign in using your existing RGID credentials. If not, you can create one on the next screen.

This won’t sign you up to anything or add you to any mailing lists. You can see our full privacy policy here.