简体   繁体   中英

I am trying to delete file from S3 bucket using python but I am not able to delete the file

>>> import boto
>>> s3 = boto.connect_s3('<access_key>', '<secret_key>')
>>> bucket = s3.lookup('donebox-static')
>>> key = bucket.new_key('testkey')
>>> key.set_contents_from_string('This is a test')
>>> key.exists()
>>> key.delete()

while deleting, i got following error. I am using Linux machine but I am able to delete file from windows machine. Error is:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/site-packages/boto-2.48.0-py2.7.egg/boto/s3/key.py", line 558, in delete
    headers=headers)
  File "/usr/lib/python2.7/site-packages/boto-2.48.0-py2.7.egg/boto/s3/bucket.py", line 762, in delete_key
    query_args_l=None)
  File "/usr/lib/python2.7/site-packages/boto-2.48.0-py2.7.egg/boto/s3/bucket.py", line 781, in _delete_key_internal
    response.reason, body)
boto.exception.S3ResponseError: S3ResponseError: 403 Forbidden
<?xml version="1.0" encoding="UTF-8"?>
<Error><Code>AccessDenied</Code><Message>Access Denied</Message><RequestId>6CF28CE4F8227FAE</RequestId><HostId>mrS5DIDHvXgweWSlwmQYVE0H05jsnepXd+3PiMqHcjXhWPkfo8ibeWA9rBcm7fKkdAO2f/fUTjo=</HostId></Error

>

Your code is perfectly fine. (I tested it on my own bucket, it worked well.)

The error message is Access Denied . This means that the entity associated with your AWS credentials (most probably your IAM User) is not permitted to delete that object. Or, most probably, any object in that bucket.

Things to check:

  • Look at the policies on your IAM User (or whatever entity is associated with the credentials you were using)
  • Look at the Bucket Policy on the donebox-static bucket

Check both of these policies to determine why you are not permitted to delete objects. Remember -- by default, you are not permitted to do anything so you're looking for a policy that does grant you DeleteObject permissions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM