3

I'm trying to upload a file to a specific location using boto and python. I'm accessing using something to this effect:

from boto.s3.connection import S3Connection
from boto.s3.key import Key


conn = S3Connection(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)
bucket = conn.get_bucket('the_bucket_name')
for key in bucket: 
    print key.name

Here's the trick. I have been provisioned credentials to a 'folder' within a bucket. per this - Amazon S3 boto - how to create a folder? I understand that there actually aren't folders in s3, rather keys like "foo/bar/my_key.txt". when i try to execute get_bucket() I get

boto.exception.S3ResponseError: S3ResponseError: 403 Forbidden

because i dont actually have credentials to the base bucket, rather a subset of the bucket keys. my_bucket/the_area_I_have_permission/*

Does anyone know how I could pass the specific 'area' in the bucket i have access to in the connection step? or an alternative method i can use to access my_bucket/the_area_I_have_permission/* ?

Community
  • 1
  • 1
Brad
  • 6,106
  • 4
  • 31
  • 43

2 Answers2

2

Does this help :

bucket = conn.get_bucket('the_bucket_name',validate=False)

key = bucket.get_key("ur_key_name")
if key is not None:
    print  key.get_contents_as_string()

keys = bucket.list(prefix='the_area_I_have_permission')
for key in keys:
    print key.name
Archit Jain
  • 2,154
  • 1
  • 18
  • 32
  • thanks for the reply. nope. got TypeError: get_key() got an unexpected keyword argument 'prefix' for the first and boto.exception.S3ResponseError: S3ResponseError: 403 Forbidden for the second. – Brad Jul 09 '13 at 14:13
  • Ohh mixed two different API calls. This one should be the call. Regarding 403, Are you able to access the bucket using some other clinet(may be UI or S3Explorer plugin for Firefox) with these secretid/keys ? – Archit Jain Jul 09 '13 at 14:34
  • dang. I still get a 403 for the first. I'm trying to connect with "bucket-name", then i'm passing the path to the file i'm trying to access ie: "/some/path/file.json". is that correct? i've tried with and without the leading slash. – Brad Jul 09 '13 at 14:42
  • as for the 403, yes. I connect just fine with s3uploader BUT if i try to navigate anywhere but the specific folder i've been provisioned creds for, I get the error – Brad Jul 09 '13 at 14:48
1

Found the problem. RequestTimeTooSkewed Error using PHP S3 Class

The issue was my VM date was off and amazon uses the date to validate the request. 1+ to @bdonlan.

Community
  • 1
  • 1
Brad
  • 6,106
  • 4
  • 31
  • 43