How to quickly upload your Play Framework web app to AWS Elastic Beanstalk
- Create your Play Framework application and initialize the project as a git repository.
- Install AWS CLI.
- Create your elastic beanstalk application environment using the Docker container in the online AWS Elastic Beanstalk Management Console.
- Create configuration files (Dockerfile, Dockerrun.aws.json and, optionally, .ebextentions/*.conf) in the project top directory.
- 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
- Change the variables (APP_NAME, APP_VERSION, EB_BUCKET, EB_APP and EB_ENV) depending on your development environment.
- 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.
- Update your Play application code
git add . && git commit -m "commit message"
./aws.sh
- Open the Elastic Beanstalk Management Console in your web browser:
eb console
- Wait for a few minutes untill the environment update is completed.
- View your latest Play application in production in your web browser:
eb open