Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django-compressor, heroku, s3: Request has expired

I am using django-compressor on heroku with amazon s3 serving static files and I keep running into the following error with the compressor generated links to static files. I am totally new to compressor and s3:

https://xxx.s3.amazonaws.com/static/CACHE/css/989a3bfc8147.css?Signature=tBJBLUAWoA2xjGlFOIu8r3SPI5k%3D&Expires=1365267213&AWSAccessKeyId=AKIAJCWU6JPFNTTJ77IQ

<Error>
<Code>AccessDenied</Code>
<Message>Request has expired</Message>
<RequestId>FE4625EF498A9588</RequestId>
<Expires>2013-04-06T16:53:33Z</Expires>
<HostId>Fbjlk4eigroefpAsW0a533NOHgfQBG+WFRTJ392v2k2/zuG8RraifYIppLyTueFu</HostId>
<ServerTime>2013-04-06T17:04:41Z</ServerTime>
</Error>

I have two heroku servers configured, one for staging and one for production. They each have their own database and s3 bucket. They also share the same settings file, all unique settings are configured as environment vars. I have checked that the static files are in fact being pushed to their respective buckets.

compressor & s3 settings are as follows:

COMPRESS_ENABLED = True
COMPRESS_STORAGE = STATICFILES_STORAGE 
COMPRESS_URL = STATIC_URL
COMPRESS_ROOT = STATIC_ROOT
COMPRESS_OFFLINE = False

AWS_ACCESS_KEY_ID = os.environ.get('AWS_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY = os.environ.get('AWS_SECRET_ACCESS_KEY')
AWS_STORAGE_BUCKET_NAME = os.environ.get('AWS_STORAGE_BUCKET_NAME')

Each time I push an update to heroku on staging or production, I eventually run into the above issue. Sometimes it happens after an hour, sometimes a day, sometimes a week, and sometimes as soon as an update is pushed out. The odd thing is that, if I push the same update to both environments, one will work and I will get the error on the other or they will both work at first and one will expire in an hour and the other will expire in a week.

I would really appreciate it if someone could explain what is going on. Obviously the Expires parameter is causing the problem, but why would the duration change with each push and what determines the amount of time? HOW DO YOU CHANGE THE EXPIRATION TIME? Please let me know if you need any more info.

UPDATE: I temporarily solved the problem by setting AWS_QUERYSTRING_AUTH = False. There does not seem to be any way to set the EXPIRATION TIME in the query string, only using in the request header.

like image 229
Arctelix Avatar asked Apr 06 '13 17:04

Arctelix


1 Answers

Give this a try:

AWS_QUERYSTRING_EXPIRE = 63115200

The value being number of seconds from the time the links are generated.

like image 148
mjacksonw Avatar answered Sep 29 '22 22:09

mjacksonw