Estos son mis permisos:
{
"Version": "2012-10-17",
"Id": "http referer policy example",
"Statement": [
{
"Sid": "Allow get requests originating from transportool-test.herokuapp.com and localhost.",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::mi-dominio/*",
"Condition": {
"StringLike": {
"aws:Referer": [
"https://mi-dominio.com/*",
"http://localhost/*",
"http://127.0.0.1:8000/*"
]
}
}
}
]
}
Y los permisos que tengo son:
Bucket owner (your AWS account)
List, Write
Read, Write
S3 log delivery group
List, Write
Read, Write
Everyone (public access) -> Sin permisos
Authenticated users group (anyone with an AWS account)->Sin permisos
Subo los archivos sin problemas pero a la hora de obtenerlos vía recibo un 403:
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<Error>
<Code>AccessDenied</Code>
<Message>Access Denied</Message>
<RequestId>8GW3XXXP2RMKC1VF1AQ</RequestId>
<HostId>kyP9qu1o/SRD7fgmoFEpTqUQWDU6lYC/ykw/0SuiLUxtKudf/pesnr4imRskLyprdBy9zsOTUjzyVddddddTI=</HostId>
</Error>
Esta es mi función para recibirlo, hay que tener en cuenta de que las KEYS y todas las credenciales están correctas, ya que al subir otros archivos con la directiva ACL="public-read" no tengo problema ni al subirlos ni al obtenerlos. Debe ser algo de permisos que se me escapa. He probado también a poner los permisos públicos de Read en Everyone (public access) y en Authenticated users group (anyone with an AWS account) y nada.
BUCKET_NAME = settings.AWS_STORAGE_BUCKET_NAME
BUCKET_FILE_NAME = uploadFiles.path
print(BUCKET_NAME)
print(BUCKET_FILE_NAME)
s3 = boto3.client('s3',
region_name=settings.AWS_REGION_HOST_NAME,
aws_access_key_id=settings.AWS_ACCESS_KEY_ID,
aws_secret_access_key=settings.AWS_SECRET_ACCESS_KEY)
s3_response_object = s3.get_object(Bucket=BUCKET_NAME, Key=BUCKET_FILE_NAME)
print("s3_response_object")
print(s3_response_object)
s3_response_object['Body'] = s3_response_object['Body'].read().decode("ISO-8859-1")
s3_response_object['Key'] = settings.AWS_ACCESS_KEY_ID + '/' + settings.AWS_SECRET_ACCESS_KEY
print(s3_response_object['Key'])
location = s3.get_bucket_location(Bucket=BUCKET_NAME)['LocationConstraint']
print(location)
url = "https://s3-%s.amazonaws.com/%s/%s" % (location, BUCKET_NAME, BUCKET_FILE_NAME)
print(url)
s3_response_object['URL'] = url
result = {}
response_data = json.dumps(s3_response_object, default=myconverter)
mimetype = 'application/json'
return HttpResponse(response_data, mimetype)