Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Amazon Web Services for Haskell
Haskell
tag: 0.3.2

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
Aws
Examples
misc/AmazonSimpleDB-2009-04-15-scratchpad/webapp
.gitignore
Aws.hs
LICENSE
README.org
Setup.hs
aws.cabal
ghci.hs

README.org

Amazon Web Services for Haskell

Introduction

The aws package attempts to provide support for using Amazon Web Services like S3 (storage), SQS (queuing) and others to Haskell programmers. The ultimate goal is to support all Amazon Web Services.

Installation

Make sure you have a recent GHC installed, as well as cabal-install, and installation should be as easy as:

$ cabal install aws

If you prefer to install from source yourself, you should first get a clone of the aws repository, and install it from inside the source directory:

$ git clone https://github.com/aristidb/aws.git
$ cd aws
$ cabal install

Using aws

Concepts and organisation

The aws package is organised into the general Aws module namespace, and subnamespaces like Aws.S3 for each Amazon Web Service. Under each service namespace in turn, there are general support modules and and Aws.<Service>.Commands.<Command> module for each command. For easier usage, there are the “bundling” modules Aws (general support), and Aws.<Service>.

The primary concept in aws is the Transaction, which corresponds to a single HTTP request to the Amazon Web Services. A transaction consists of a request and a response, which are associated together via the Transaction typeclass. Requests and responses are simple Haskell records, but for some requests there are convenience functions to fill in default values for many parameters.

Example usage

To be able to access AWS resources, you should put your into a configuration file. (You don’t have to store it in a file, but that’s how we do it in this example.) Save the following in $HOME/.aws-keys.

default AccessKeyID SecretKey

You do have to replace AccessKeyID and SecretKey with the Access Key ID and the Secret Key respectively, of course.

Then, copy this example into a Haskell file, and run it with runghc:

{-# LANGUAGE OverloadedStrings #-}

import qualified Aws
import qualified Aws.S3 as S3
import Data.Conduit
import Data.Conduit.Binary
import Data.IORef
import Data.Monoid

{- A small function to save the object's data into a file. -}
saveObject :: Aws.HTTPResponseConsumer ()
saveObject status headers source = source $$ sinkFile "cloud-remote.pdf"

main :: IO ()
main = do
  {- Set up AWS credentials and the default configuration. -}
  cfg <- Aws.baseConfiguration

  {- Create an IORef to store the response Metadata (so it is also available in case of an error). -}
  metadataRef <- newIORef mempty

  {- Create a request object with S3.getObject and run the request with simpleAwsRef. -}
  Aws.simpleAwsRef cfg metadataRef $ S3.getObject "haskell-aws" "cloud-remote.pdf" saveObject

  {- Print the response metadata. -}
  print =<< readIORef metadataRef

You can also find this example in the source distribution in the Examples/ folder.

Release Notes

0.3 series

0.3.2
Add awsRef / simpleAwsRef request variants for those who prefer an IORef over a Data.Attempt.Attempt value. Also improve README and add simple example.

Resources

Something went wrong with that request. Please try again.