Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
82 lines (51 sloc) 2.13 KB

Build Status Build Status

clj-aws-ec2

A Clojure library for accessing Amazon EC2, based on the official AWS Java SDK and borrowing heavily from James Reeves's clj-aws-s3 library.

This is a very early development version. Currently the library only supports functions to list/describe EC2 reservations, instances and machine images (AMIs), and to start and stop EBS-backed instances. See TODO for future plans.

Install

Add the following dependency to your project.clj file:

[clj-aws-ec2 "0.1.5"]

Example

(require '[aws.sdk.ec2 :as ec2])

(def cred {:access-key "...", :secret-key "..."})

(ec2/describe-instances cred)
(ec2/describe-instances cred (ec2/instance-id-filter "i-deadcafe"))

(ec2/describe-images cred (image-owner-filter "self"))
(ec2/describe-images cred (image-id-filter "ami-3c47a355"))

(ec2/start-instances cred "i-beefcafe")
(ec2/stop-instances cred "i-beefcafe" "i-deadbabe")

Using regions

To use a region other than us-east-1 you can specify an API endpoint in the credentials map:

(def cred {:access-key "...", :secret-key "...", :endpoint "ap-southeast-2"})

Refer to Regions and Endpoints for a list of current EC2 endpoints.

Exception handling

You can catch exceptions and extract details of the error condition:

(try
  (ec2/start-instances cred "i-beefcafe")
  (catch Exception e (ec2/decode-exception e)))

ec2/decode-exception provides a map with the following keys:

:error-code
:error-type
:service-name
:status-code

Documentation

License

Copyright (C) 2012 Michael Rowe

Distributed under the Eclipse Public License, the same as Clojure.

Jump to Line
Something went wrong with that request. Please try again.