Skip to content

Instantly share code, notes, and snippets.

@groveriffic
Created July 9, 2013 19:17
Show Gist options
  • Save groveriffic/5960369 to your computer and use it in GitHub Desktop.
Save groveriffic/5960369 to your computer and use it in GitHub Desktop.
-- Prerequisites:
-- Boto: sudo pip install boto
-- Boto Config File: see https://code.google.com/p/boto/wiki/BotoConfig
-- Add PL Language Extensions
CREATE EXTENSION IF NOT EXISTS plpythonu;
CREATE OR REPLACE FUNCTION _s3_get(bucket text, key text)
RETURNS bytea AS $$
import boto # AWS SDK
conn = boto.connect_s3()
b = conn.get_bucket(bucket)
k = b.get_key(key)
return k.get_contents_as_string()
$$ LANGUAGE plpythonu IMMUTABLE STRICT;
CREATE OR REPLACE FUNCTION _s3_put(bucket text, key text, data bytea)
RETURNS bool AS $$
import boto # AWS SDK
from boto.s3.key import Key
conn = boto.connect_s3()
b = conn.get_bucket(bucket)
k = Key(b)
k.key = key
k.set_contents_from_string(data)
return True
$$ LANGUAGE plpythonu IMMUTABLE STRICT;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment