0

I have given 'everyone' as all permissions in AWS s3 bucket permissions.

Ia m using django. I am able to read the files but i am not able to write it.

I am trying this

>>> print default_storage.connection
S3Connection:s3.amazonaws.com
>>> from django.core.files.base import ContentFile
>>> from django.core.cache import cache

>>> default_storage.exists('testkey')
True



>>> file = default_storage.open('storage_test', 'w')
>>> file.write('storage contents')
Traceback (most recent call last):


S3ResponseError: S3ResponseError: 403 Forbidden
<?xml version="1.0" encoding="UTF-8"?>
<Error><Code>AccessDenied</Code><Message>Access Denied</Message><RequestId>FDD54

I have added this in settings

DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
AWS_ACCESS_KEY_ID='XXXXXXXXXXXXXXA'
AWS_SECRET_ACCESS_KEY='XXXXXXX'
AWS_STORAGE_BUCKET_NAME='testbucket'

I am also confused how to django s3 knows which user to use from s3 . i am confused. The access key is for the user_123 which i created but in permission i am not able to see that user in aws s3 dropdown

user1958218
  • 1,571
  • 3
  • 18
  • 28
  • Would this help? http://stackoverflow.com/questions/10854095/boto-exception-s3responseerror-s3responseerror-403-forbidden – karthikr Jun 23 '13 at 15:05

1 Answers1

5

I am also confused how to django s3 knows which user to use from s3

This is determined strictly by the Accesskey and secret key you placed in your config.

Did you give user_123 access to S3? In the IAM console, you need to give user_123 access to the bucket like this:

{
  "Statement": [
    {
      "Effect": "Allow",
      "Action": "s3:*",
      "Resource": ["arn:aws:s3:::testbucket/*", "arn:aws:s3:::testbucket"]
    }
  ]
}

Don't forget to remove 'Everyone's permission to the bucket

prestomation
  • 7,225
  • 3
  • 39
  • 37
  • but where is `user_123` written in that policy – user1958218 Jun 24 '13 at 23:31
  • The policy is attached to user_123. In the IAM console, select users->user_123->Permissions tab->"Attack User Policy" and paste the above policy in. It will apply to user_123 by virtue of being attached to user_123 – prestomation Jun 25 '13 at 00:09