Skip to content

Commit

Permalink
Added ability to terminate an environment.
Browse files Browse the repository at this point in the history
  • Loading branch information
ck committed Feb 10, 2011
1 parent 8c09e5d commit 4fe4085
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 13 deletions.
30 changes: 21 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Leiningen plugin for Amazon's [Elastic Beanstalk][1]
## Prerequisites

You will need an [Amazon Web Services][2] account, and know your
account key and secret key.
account key and secret key.

You will also need to be signed up for Elastic Beanstalk.

Expand All @@ -25,12 +25,14 @@ environments:

:aws {:access-key "XXXXXXXXXXXXXXXXXX"
:secret-key "YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY"}
:beanstalk {:environments [myapp-development myapp-staging myapp-production]}}
:beanstalk {:environments [development staging production]}}

### Deploy

You should now be able to deploy your application to the Amazon cloud
using the following command:

lein beanstalk deploy myapp-dev
$ lein beanstalk deploy development

### Info

Expand All @@ -46,18 +48,18 @@ To get information about the application itself run
0.1.0-20110209015216
Created On : Wed Feb 09 03:00:45 EST 2011
Updated On : Wed Feb 09 03:00:45 EST 2011
Deployed Envs : myapp-development (Ready)
myapp-staging (Ready)
myapp-production (Terminated)
Deployed Envs : development (Ready)
staging (Ready)
production (Terminated)

and information about a particular environment execute

$ lein beanstalk info myapp-development
$ lein beanstalk info development
Environment Id : e-lm32mpkr6t
Application Name : myapp
Environment Name : myapp-development
Environment Name : development
Description : Default environment for the myapp application.
URL : myapp.elasticbeanstalk.com
URL : development-feihvibqb.elasticbeanstalk.com
LoadBalancer URL : awseb-myapp-46156215.us-east-1.elb.amazonaws.com
Status : Ready
Health : Green
Expand All @@ -66,6 +68,16 @@ and information about a particular environment execute
Created On : Tue Feb 08 08:01:44 EST 2011
Updated On : Tue Feb 08 08:05:01 EST 2011

### Shutting Down

To shutdown an existing environment use the following command

$ lein beanstalk terminate development

This terminate the environment and all of its resources, i.e.
the Auto Scaling group, LoadBalancer, etc.


## Trouble-Shooting

Q: Why does my deployed web application still shows up as 'red' in the
Expand Down
18 changes: 14 additions & 4 deletions src/leiningen/beanstalk.clj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@
(aws/create-app-version project filename)
(aws/deploy-environment project environment)))))

(defn terminate
"Terminte the environment for the current project on Amazon Elastic Beanstalk."
([project]
(println "Usage: lein beanstalk terminate <environment>"))
([project env-name]
(if-not (project-env-exists? project env-name)
(println (str "Environment '" env-name "' not in project.clj"))
(aws/terminate-environment project env-name))))

(def app-info-indent "\n ")

(defn- last-versions-info [app]
Expand Down Expand Up @@ -78,11 +87,12 @@

(defn beanstalk
"Manage Amazon's Elastic Beanstalk service."
{:help-arglists '([deploy info])
:subtasks [#'deploy #'info]}
{:help-arglists '([deploy info terminate])
:subtasks [#'deploy #'info #'terminate]}
([project]
(println (help-for "beanstalk")))
([project subtask & args]
(case subtask
"deploy" (apply deploy project args)
"info" (apply info project args))))
"deploy" (apply deploy project args)
"info" (apply info project args)
"terminate" (apply terminate project args))))
10 changes: 10 additions & 0 deletions src/leiningen/beanstalk/aws.clj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
com.amazonaws.services.elasticbeanstalk.model.DescribeEnvironmentsRequest
com.amazonaws.services.elasticbeanstalk.model.UpdateEnvironmentRequest
com.amazonaws.services.elasticbeanstalk.model.S3Location
com.amazonaws.services.elasticbeanstalk.model.TerminateEnvironmentRequest
com.amazonaws.services.s3.AmazonS3Client))

(defn credentials [project]
Expand Down Expand Up @@ -95,3 +96,12 @@
(if-let [env (get-environment project env-name)]
(update-environment project env)
(create-environment project env-name)))

(defn terminate-environment
[project env-name]
(if-let [env (get-environment project env-name)]
(.terminateEnvironment
(beanstalk-client project)
(doto (TerminateEnvironmentRequest.)
(.setEnvironmentId (.getEnvironmentId env))
(.setEnvironmentName (.getEnvironmentName env))))))

0 comments on commit 4fe4085

Please sign in to comment.