djangoamazon-s3boto3python-django-storages

Use Django-Storages with IAM Instance Profiles


Django-Storages provides an S3 file storage backend for Django. It lists AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY as required settings. If I am using an AWS Instance Profile to provide S3 access instead of a key pair, how do I configure Django-Storages?


Solution

  • You simply omit these parameters from your settings.

    The Django-Storages documentation now explains this:

    If AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY are not set, boto3 internally looks up IAM credentials.

    The way this works under the hood is that if you do not provide them, Django-Storages passes None to boto3, which uses the machine's privileges instead of a key pair. If the machine has an associated Instance Profile, this is what gets used. (See the boto3 docs for more on boto3's credential hierarchy)


    Thanks to @ChrisShenton for pointing out that the Django-Storages docs had been updated. The Django-Storages docs previously listed these configuration parameters as required, which was incorrect.