Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VPC support #38

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,20 @@ If the environment variable name is a keyword, it is upper-cased and
underscores ("_") are substituted for dashes ("-"). e.g.
`:database-url` becomes `"DATABASE_URL"`.

### VPC options

You can specify the VPC options of an environment.
```clojure
:aws
{:beanstalk
{:environments
[{:name "dev"
:vpc {"VPCId" "vpc-43498"
"Subnets" "subnet-32c4595f"
"ELBSubnets" "subnet-35c4595d"
"DBSubnets" "subnet-38r4595f, subnet-4fdc9633, subnet-e9dc96554"}}]}}
```

### S3 Buckets

[Amazon Elastic Beanstalk][1] uses
Expand Down Expand Up @@ -231,6 +245,14 @@ The following regions are recognized:
* `us-west-1`
* `us-west-2`

### Proxy

You can specify the proxy server to use for deployment
your `project.clj` file:
```clojure
:aws {:beanstalk {:proxy-host "proxy.host"
:proxy-port 1080}}
```

## Trouble-Shooting

Expand Down
25 changes: 21 additions & 4 deletions src/leiningen/beanstalk/aws.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
java.text.SimpleDateFormat
java.util.Date
[java.util.logging Logger Level]
com.amazonaws.ClientConfiguration
com.amazonaws.auth.BasicAWSCredentials
com.amazonaws.services.elasticbeanstalk.AWSElasticBeanstalkClient
com.amazonaws.services.elasticbeanstalk.model.ConfigurationOptionSetting
Expand Down Expand Up @@ -78,17 +79,24 @@
(when-not (.doesBucketExist client bucket)
(.createBucket client bucket)))

(defn- client-configuration [project]
"Create an instance of ClientConfiguration with the proxies set, if available"
(let [client-config (ClientConfiguration.)]
(when (-> project :aws :beanstalk :proxy-host) (.setProxyHost client-config (-> project :aws :beanstalk :proxy-host)))
(when (-> project :aws :beanstalk :proxy-port) (.setProxyPort client-config (-> project :aws :beanstalk :proxy-port)))
client-config))

(defn s3-upload-file [project filepath]
(let [bucket (s3-bucket-name project)
file (io/file filepath)]
(doto (AmazonS3Client. (credentials project))
(doto (AmazonS3Client. (credentials project) (client-configuration project))
(.setEndpoint (project-endpoint project s3-endpoints))
(create-bucket bucket)
(.putObject bucket (.getName file) file))
(println "Uploaded" (.getName file) "to S3 Bucket")))

(defn- beanstalk-client [project]
(doto (AWSElasticBeanstalkClient. (credentials project))
(doto (AWSElasticBeanstalkClient. (credentials project) (client-configuration project))
(.setEndpoint (project-endpoint project beanstalk-endpoints))))

(defn create-app-version
Expand Down Expand Up @@ -140,6 +148,15 @@
key)
value)))

(defn vpc-options [project options]
(for [[key value] (:vpc options)]
(ConfigurationOptionSetting.
"aws:ec2:vpc"
(if (keyword? key)
(-> key name str/upper-case (str/replace "-" "_"))
key)
value)))

(defn create-environment [project env]
(println (str "Creating '" (:name env) "' environment")
"(this may take several minutes)")
Expand All @@ -149,7 +166,7 @@
(.setApplicationName (app-name project))
(.setEnvironmentName (:name env))
(.setVersionLabel (app-version project))
(.setOptionSettings (env-var-options project env))
(.setOptionSettings (into (env-var-options project env) (vpc-options project env)))
(.setCNAMEPrefix (:cname-prefix env))
(.setSolutionStackName (or (-> project :aws :beanstalk :stack-name)
"32bit Amazon Linux running Tomcat 7")))))
Expand All @@ -160,7 +177,7 @@
(doto (UpdateEnvironmentRequest.)
(.setEnvironmentId (.getEnvironmentId env))
(.setEnvironmentName (.getEnvironmentName env))
(.setOptionSettings (env-var-options project options)))))
(.setOptionSettings (into (env-var-options project env) (vpc-options project env))))))

(defn update-environment-version [project env]
(.updateEnvironment
Expand Down