I have a Django app deployed on Heroku, where users submit images via Amazon S3.
Though, when serving the image using {{ image.url }}
in my Django template, the server seems to request a signed URL from S3 for every single image, and this takes a few seconds for each image, making the site painfully slow (17 seconds to load 9 small images).
I can see the request for each image in the logs:
Sending http request: <AWSPreparedRequest stream_output=True, method=GET, url=https://x.s3.ap-southeast-1.amazonaws.com/x.jpg, ...>
Is there a way of serving the images without waiting for a response from S3? How can I optimize this?
Here is my S3 config in settings.py
:
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 = "x"
AWS_S3_FILE_OVERWRITE = False
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…