etianen / django-s3-storage

Django Amazon S3 file storage.
BSD 3-Clause "New" or "Revised" License
414 stars 94 forks source link

In AWS Lambda, InvalidAccessKeyId error unless AWS_SESSION_TOKEN is given #68

Closed ceefour closed 6 years ago

ceefour commented 6 years ago

Using django-s3-storage in Lambda (for example with zappa) will throw InvalidAccessKey error because it doesn't give AWS_SESSION_TOKEN which is required for temporary security credentials given by Lambda. e.g.

botocore.exceptions.ClientError: An error occurred (InvalidAccessKeyId) when calling the ListObjectsV2 operation: The AWS Access Key Id you provided does not exist in our records.

How to fix this:

  1. Support AWS_SESSION_TOKEN in Django settings.py (and also add it to README/docs)
  2. Pass that token to boto3
etianen commented 6 years ago

I've added this feature to the master branch. Please let me know if it works for you.

thesunlover commented 6 years ago

how to use AWS_SESSION_TOKEN to overcome this issue? The generated by aws sts get-token AWS_SESSION_TOKEN is only valid for a limited time ... so i cannot start the server for unlimited period with this token

ceefour commented 5 years ago

Thank you @etianen

AFAIK AWS_SESSION_TOKEN is used by AWS Lambda, i.e. in combination with Zappa.