Permalink
Browse files

Allow an API endpoint to be specified (enabling use of regions other …

…than us-east).
  • Loading branch information...
1 parent 3995346 commit ed55642ac3fcda6b5ab4719accbbc027dc0e2dd0 @mrowe mrowe committed Nov 13, 2012
Showing with 24 additions and 7 deletions.
  1. +14 −1 README.md
  2. +1 −1 project.clj
  3. +9 −5 src/aws/sdk/ec2.clj
View
@@ -17,7 +17,7 @@ machine images (AMIs). See [TODO][] for future plans.
Add the following dependency to your `project.clj` file:
- [clj-aws-ec2 "0.1.4"]
+ [clj-aws-ec2 "0.1.5"]
## Example
@@ -37,6 +37,19 @@ Add the following dependency to your `project.clj` file:
```
+### Using regions
+
+To use a region other than `us-east-1` you can specify an API endpoint
+in the credentials map:
+
+```clojure
+(def cred {:access-key "...", :secret-key "..." :endpoint "ap-southeast-2"})
+```
+
+Refer to [Regions and Endpoints][] for a list of current EC2 endpoints.
+
+[Regions and Endpoints]: http://docs.amazonwebservices.com/general/latest/gr/rande.html#ec2_region
+
### Exception handling
You can catch exceptions and extract details of the error condition:
View
@@ -1,4 +1,4 @@
-(defproject clj-aws-ec2 "0.1.4"
+(defproject clj-aws-ec2 "0.1.5"
:description "Clojure Amazon EC2 library."
:url "https://github.com/mrowe/clj-aws-ec2"
:license {:name "Eclipse Public License"
View
@@ -2,7 +2,9 @@
"Functions to access the Amazon EC2 compute service.
Each function takes a map of credentials as its first argument. The
- credentials map should contain an :access-key key and a :secret-key key."
+ credentials map should contain an :access-key key and a :secret-key
+ key. It can also contain an optional :endpoint key if you wish to
+ specify an API endpoint (i.e. region) other than us-east."
(:import com.amazonaws.AmazonServiceException
com.amazonaws.auth.BasicAWSCredentials
com.amazonaws.services.ec2.AmazonEC2Client
@@ -29,10 +31,12 @@
(defn- ec2-client*
"Create an AmazonEC2Client instance from a map of credentials."
[cred]
- (AmazonEC2Client.
- (BasicAWSCredentials.
- (:access-key cred)
- (:secret-key cred))))
+ (let [client (AmazonEC2Client.
+ (BasicAWSCredentials.
+ (:access-key cred)
+ (:secret-key cred)))]
+ (if (:endpoint cred) (.setEndpoint client (:endpoint cred)))
+ client))
(def ^{:private true}
ec2-client

0 comments on commit ed55642

Please sign in to comment.