Congnitect Labs AWS APIλ︎
Congnitect Labs AWS API is an idiomatic, data-oriented Clojure library for invoking AWS APIs.
AWS APIs are described in data that specifies operations, inputs and outputs.
aws-api uses the data descriptions to expose a data-oriented interface, using service descriptions, documentation and specs generated from the source descriptions.
Data descriptions are versioned, e.g. com.cognitect.aws/dynamo-db-653.2.351.0
AWS API uses data descriptions from aws-sdk-js but does not wrap the any language SDK, which would tie you to that workflow
The main functions are
client
- create a client for a given serviceinvoke
- an operation on the service (assumption:? via the client), takes and returns a hash-map
Helper functions:
Library Dependenciesλ︎
S3 Bucket
com.cognitect.aws/api {:mvn/version "0.8.666"}
com.cognitect.aws/endpoints {:mvn/version "1.1.12.456"}
com.cognitect.aws/s3 {:mvn/version "847.2.1365.0"}
REPL workflowλ︎
Create a project with a deps.edn
file that contains the library dependencies for Cognitect Labs AWS API.
Require the client API.
Create a client
Ask what operations the client can perform
Request documentation for an operation
Instruct the client to validate requests, reporting when incorrect arguments are used
List the S3 buckets
(aws/invoke s3 {:op :ListBuckets})
;; => {:Buckets [{:Name <name> :CreationDate <date> ,,,}]}
Get the meta data from the previous expression, i.e. list buckets
http-request and http-response are in the metadata
```clojure
(meta *1)
;; => {:http-request {:request-method :get,
;; :scheme :https,
;; :server-port 443,
;; :uri "/",
;; :headers {,,,},
;; :server-name "s3.amazonaws.com",
;; :body nil},
;; :http-response {:status 200,
;; :headers {,,,},
;; :body <input-stream>}
Create bucket in the same region as client
Create a bucket in a region other than us-east-1
(aws/invoke s3 {:op :CreateBucket :request {:Bucket "my-unique-bucket-name-in-us-west-1"
:CreateBucketConfiguration
{:LocationConstraint "us-west-1"}}})
NOTE: be sure to create a client with region "us-west-1" when accessing that bucket.