Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[Caml-list] OCaml S3 Library?

65 views
Skip to first unread message

Daniel Patterson

unread,
May 12, 2010, 6:29:55 PM5/12/10
to caml...@yquem.inria.fr
Has anyone written a library to interact with amazon web services
(specifically, S3)?

I started writing one, but something about the authentication is not working
properly, and I thought I'd check to see if anyone had already done this
before I try to figure out what is going wrong. Sample code follows, as if
there does not already exist a library, I'd be curious if anyone else sees
what is wrong with the authentication signature (what I assume is not
working), as now it 403's every time.

open Netencoding.Base64
open Cryptokit
open Cryptokit.MAC
open Http_client

let id = "___PUT_YOUR_ID_HERE____"
let key = "__PUT_YOUR_SECRET_KEY_HERE____"

let sign verb content_type date bucket url =
let hash = hmac_sha1 key in
let str_to_sign = verb ^ "\n\n" ^ content_type ^ "\n" ^ date ^ "\n" ^
"/" ^ bucket ^ url in
begin
Printf.printf "---------\n%s\n---------\n" str_to_sign;
"AWS " ^ id ^ ":" ^ encode (hash_string hash str_to_sign)
end

let date () = Netdate.mk_mail_date (Unix.time ())

let text_put_s3 bucket url contents =
let uri = "http://" ^ bucket ^ ".s3.amazonaws.com" ^ url in
let req = new put uri contents in
let head = req#request_header `Base in
let content_type = "text/plain" in
let now = date () in
let pipeline = new pipeline in
begin
pipeline#set_options {pipeline#get_options with verbose_status=true;
verbose_request_header=true; verbose_response_header=true;
verbose_request_contents=true;
verbose_response_contents=true; verbose_connection=true};
head#set_fields [("Date", now); ("Content-Type", content_type);
("Authentication", sign "PUT" content_type now bucket url)];
req#set_request_header head;
pipeline#add req;
pipeline#run ();
(req#response_status_code, req#response_status_text)
end

let _ = text_put_s3 "__BUCKET_NAME__" "/test" "This is a Test."

Jerome Vouillon

unread,
May 13, 2010, 9:31:17 AM5/13/10
to Daniel Patterson, caml...@yquem.inria.fr
On Wed, May 12, 2010 at 06:26:39PM -0400, Daniel Patterson wrote:
> Has anyone written a library to interact with amazon web services
> (specifically, S3)?

I have started writing a library for S3. A large part of the API is
implemented. What is missing is mostly dealing with metadata and
error handling.

You can find the current sources here:

http://www.pps.jussieu.fr/~vouillon/S3.tar.gz

If anyone is interested to contribute, please contact me. I will then
set up a shared repository.

-- Jerome

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

0 new messages