How to quickly upload your Play Framework web app to AWS Elastic Beanstalk

  1. Create your Play Framework application and initialize the project as a git repository.
  2. Install AWS CLI.
  3. Create your elastic beanstalk application environment using the Docker container in the online AWS Elastic Beanstalk Management Console.
  4. Create configuration files (Dockerfile, Dockerrun.aws.json and, optionally, .ebextentions/*.conf) in the project top directory.
  5. Place the following bash script file as aws.sh in the top directory of your play framework application (play-scala).
#!/bin/bash

readonly APP_NAME=play-scala
readonly APP_VERSION=1.0
readonly EB_BUCKET=<name of your S3 bucket to store your app bundles> #e.g., elasticbeanstalk-us-east-1-000000000000
readonly EB_APP=<name of your elastic beanstalk application>
readonly EB_ENV=<name of your elastic beanstalk environment>
GIT_COMMIT=`git rev-parse HEAD`
GIT_MSG=`git log --oneline -1`

production_build() {
    ./activator clean compile universal:package-zip-tarball
}

build_package() {
    cd `dirname $0`/target/universal
    cp ../../Dockerfile .
    cp ../../Dockerrun.aws.json .
    cp -r ../../.ebextentions/ .
    zip -r ../aws.zip Dockerfile Dockerrun.aws.json play-scala-1.0.tgz .ebextentions/
}

eb_upload() {
    cd `dirname $0`
    aws s3api put-object --bucket $EB_BUCKET --key $GIT_COMMIT.zip --body ./target/aws.zip
    aws elasticbeanstalk create-application-version --application-name $EB_APP --description "$GIT_MSG" --version-label $GIT_COMMIT --source-bundle S3Bucket=$EB_BUCKET,S3Key=$GIT_COMMIT.zip
    aws elasticbeanstalk update-environment --environment-name $EB_ENV --version-label $GIT_COMMIT
}

production_build
build_package
eb_upload
  1. Change the variables (APP_NAME, APP_VERSION, EB_BUCKET, EB_APP and EB_ENV) depending on your development environment.
  2. Make the script executable and run it.
chmod +x aws.sh
./aws.sh


Now that the automation script is in place, you can easily upload the latest version of your application to the Elastic Beanstalk production environment by repeating the following processes.

  1. Update your Play application code
  2. git add . && git commit -m "commit message"
  3. ./aws.sh
  4. Open the Elastic Beanstalk Management Console in your web browser: eb console
  5. Wait for a few minutes untill the environment update is completed.
  6. View your latest Play application in production in your web browser: eb open