Using the SOAP Interface to S3

The following code sample illustrates how to use the SOAP interface to S3:

         import sha, hmac, base64, urllib
         
         # list buckets for Amazon s3
         
         AWSAccessKeyId='[AWSAccessKeyID]'
         AWSSecretAccessKey = '[AWSSecretAccessKey]'
         
         from SOAPpy import WSDL
         
         import sha
         
         def calcSig(key,text):
             import hmac, base64
             sig = base64.b64encode(hmac.new(key, text, sha).digest())
             return sig
         
         def ListMyBuckets(s):
             from time import gmtime,strftime
             method = 'ListAllMyBuckets'
             ts = strftime("%Y-%m-%dT%H:%M:%S.000Z", gmtime())
             text = 'AmazonS3' + method + ts
             sig = calcSig(AWSSecretAccessKey,text)
             print "ListMyBuckets: ts,text,sig->", ts, text, sig
             return s.ListAllMyBuckets(AWSAccessKeyId=AWSAccessKeyId, Â
         Timestamp=ts,Signature=sig)
         
         def CreateBucket(s, bucketName):
             from time import gmtime,strftime
             method = 'CreateBucket'
             print 'method: ', method
             ts = strftime("%Y-%m-%dT%H:%M:%S.000Z", gmtime())
             text = 'AmazonS3' + method + ts
             sig = calcSig(AWSSecretAccessKey,text)
             print "CreateBuckets: ts,text,sig->", ts, text, sig
             return s.CreateBucket(Bucket=bucketName, AWSAccessKeyId=AWSAccessKeyId, Â
         Timestamp=ts,Signature=sig) 
         
         if __name__ == '__main__':    
             s = WSDL.Proxy("http://s3.amazonaws.com/doc/2006-03-01/AmazonS3.wsdl")
             print ListMyBuckets(s)
             CreateBucket(s,"test20071126RY")
             print ListMyBuckets(s) 
      

You can learn the following about S3 from this code: