This sbt plugin allows easy deployment of web archive (.war) application files to Amazon Elastic Beanstalk.
Once configured, running sbt eb-deploy uploads your application's WAR file to S3 and deploys it to your Elastic Beanstalk environment.
A sample using Play 2.1-RC1 is included.
In project/plugins.sbt, add:
resolvers += "Play2war plugins release" at "http://repository-play-war.forge.cloudbees.com/release/"
addSbtPlugin("com.github.play2war" % "play2-war-plugin" % "0.9-RC1")
addSbtPlugin("com.joescii" % "sbt-elasticbeanstalk-plugin" % "0.0.7")(Note: You need the 0.9-SNAPSHOT build of play2-war-plugin, which supports Play 2.1 and is built from git master. For convenience, is hosted on the SQS Ivy repository included above.)
In project/Build.scala, add the following at the top of the file:
import com.joescii.sbtelasticbeanstalk.{ ElasticBeanstalk, Deployment }
import com.joescii.sbtelasticbeanstalk.ElasticBeanstalkKeys._
import com.github.play2war.plugin._Add the following settings to your project:
val main = play.Project(appName, appVersion, appDependencies).settings(
Play2WarKeys.servletVersion := "3.0",
ebAppBundle <<= Play2WarKeys.war,
ebS3BucketName := "some-bucket-name",
ebDeployments := Seq(
Deployment(
appName = "some-app-name",
envBaseName = "some-environment-name",
templateName = "my-template",
cname = "my-cname",
environmentVariables = Map("MyFavoriteColor" -> "blue")
)
),
ebRegion := "us-west-1"
)
.settings(Play2WarPlugin.play2WarSettings: _*)
.settings(ElasticBeanstalk.elasticBeanstalkSettings: _*)You must create the S3 bucket and Elastic Beanstalk app and environment specified in this file. You can specify your preferred AWS region.
Either create a file in $HOME/.aws-credentials with your AWS credentials in the following format:
accessKey = <your AWS access key>
secretKey = <your AWS secret key>
... or pass these two values as properties to sbt:
sbt -DaccessKey=your_AWS_access_key -DsecretKey=your_AWS_secret_key
Note that the .aws-credentials file takes precedence over the System properties.
In project/plugins.sbt, add:
addSbtPlugin("com.joescii" % "sbt-elasticbeanstalk-plugin" % "0.0.7")In build.sbt, add the following at the top of the file:
import com.joescii.sbtelasticbeanstalk.{ ElasticBeanstalk, Deployment }
import com.joescii.sbtelasticbeanstalk.ElasticBeanstalkKeys._Add the following settings to your project:
seq(ElasticBeanstalk.elasticBeanstalkSettings: _*)
ebAppBundle <<= Keys.`package` in Compile
ebS3BucketName := "some-bucket-name"
ebDeployments := Seq(
Deployment(
appName = "some-app-name",
envBaseName = "some-environment-name",
templateName = "my-template",
cname = "my-cname",
environmentVariables = Map("MyFavoriteColor" -> "blue")
)
)
ebRegion := "us-west-1"You must create the S3 bucket and Elastic Beanstalk app and environment specified in this file. You can specify your preferred AWS region. Note that this assumes the web application plugin you are utilizing produces a war file with the compile:package key. This is the case for Lift, for instance.
Create a file in $HOME/.aws-credentials with your AWS credentials in the following format:
accessKey = <your AWS access key>
secretKey = <your AWS secret key>
Once you've configured sbt-elasticbeanstalk as described above, run the sbt eb-deploy task. This will:
- Create a WAR file for your application;
- Upload the WAR to S3 in the bucket you specified; and
- Update your Elastic Beanstalk environment to use the new WAR.
Configuration pull: Run eb-config-pull at the sbt console to download environment configuration into eb-deploy/<app>/<env>.env.conf and eb-deploy/<app><tmpl>.tmpl.conf files.
Quick update: Run eb-quick-update at the sbt console to perform a quick update (an in-place swap of the WAR and a Tomcat7 restart).
Configuration push: Run eb-config-push at the sbt console to push local environment configurations to Elastic Beanstalk.
Wait until deployed: Run eb-wait to wait until all project environments are deployed (i.e., Ready status and Green health).
Cleaning: Run eb-clean to terminate old, inactive environments; run eb-clean-app-versions to delete old and, unused app versions.
.ebextensions: Play2-war-plugin's webappResource sbt key is set to war by default, so any directories or files in the war/ directory will be added to the generated WAR file. The included Play2 sample app has an example war/.ebextensions directory that sets some Elastic Beanstalk configuration settings.
Environment variables: You can specify an environmentVariables map in each Deployment that gets passed to your EB environments as environment variables.
API actions: Tasks prefixed with eb-api- map directly to the corresponding EB API commands. Try eb-api-describe-applications, eb-api-describe-environments, and eb-api-restart-app-server <env>.
- 0.0.7: Windows support. Decoupled from Play to support Lift, etc. Added
eb-update-version. Reads System properties when~/.aws-credentialscannot be found. - 0.0.6: Better, template-aware
eb-config-pushandeb-config-pull; addedeb-quick-update - 0.0.5: Add configuration pushing
eb-config-pushand validationeb-local-config-validate. - 0.0.4: Add configuration pulling
eb-config-pull; addeb-waitto wait until deployed; addeb-api-describe-applications,eb-api-describe-environments, andeb-api-restart-app-servertasks. - 0.0.3: Can set environment variables for each deployment; added Java6 check
- 0.0.2: Added support for deployment to multiple apps and environments
- 0.0.1: Initial release
Quinn Slack (sqs) Joe Barnes (joescii)
This code is open source software licensed under the Apache 2.0 License.
