Use Django-Storages with IAM Instance Profiles
Asked Answered
E

2

5

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?

Electricity answered 19/9, 2017 at 18:28 Comment(0)
E
12

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.

Electricity answered 19/9, 2017 at 18:28 Comment(0)
N
1

The docs now explain this:

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

Nuzzi answered 21/5, 2020 at 19:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.