New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error upload file. Use zappa+ lambda + s3 + django2 + RDS. #606
Comments
Try to downgrade the installed version, it works for me. pip install django-storages==1.6.6 |
How can I reproduce the issue? |
The issue appears to be the new behaviour of django-storages to automatically pull the AWS security token from environment variables. AWS Lambda provides I was able to fix the issue by subclassing from storages.backends.s3boto3 import S3Boto3Storage
class SecurityTokenWorkaroundS3Boto3Storage(S3Boto3Storage):
def _get_security_token(self):
return None |
I suppose the solution needs to be a django setting e.g. While AWS Lambda also populates the environment with |
Thanks for the investigation. I’m trying to figure out the cleanest way for this to work for everyone. My use case is obviously different but it’s clear that there are a lot of different way this can be setup. As an initial step I am leaning towards partially reverting b13efd9. Would you be willing to write up some docs for some ways to configure access? A different user opened #458 which would remove all of the explicit settings which it seems would break your described use case as well. |
@jschneier certainly happy to help. Looking at b13efd9 -- it seems that the issue had not been a problem in my case because I had explicitly set if not self.access_key and not self.secret_key:
...
self.security_token = self._get_security_token() was never called because So, for me reverting b13efd9 would fix the issue, but it doesn't fix the underlying problem -- I think other users who aren't explicitly setting Whether or not my original idea of Alternatively, and probably the proper approach, is to provide permission to the S3 bucket in the AWS Lambda execution role. This might fix my issue without needing change in django-storages, and it would mean that #458 also wouldn't cause any issues. For me it would require updating quite a few production sites, which I don't mind if it's the proper approach, though I wonder how many other people are in the same boat now that Zappa is quite popular. I'll open a PR and add a section in |
I ran into this issue too, using the same services/frameworks as @davidllauce. I had The solution posted by @dpretty to override |
this didn't work for my case: zappa + role. Each time the request fails. |
Can anyone say if this is connected to setting the following header as named by AWS docs:
from this page: Also, my research showed that |
Is possible to be a problem with old and new credentials of the lambda-role. |
How about adding a new custom class to the lib?
|
Or if my PR is accepted:
|
Hi I am facing the same issue even when I have |
I'm facing the same error using Django + Zappa + S3 Storages |
This worked for me. My requirements.txt:
Thanks @dpretty |
It works for me using the tip that @guilhermej said. |
Where do I put this code in django? |
Did you find a solution to this? |
removing AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY solve this problem in my case. |
if these attributes removed from settings how would django-storages access s3. |
I have added this code in |
You need to add this in whatever file you are mentioning in your settings file as storage backend. @dpretty you saved the day! |
Hi all. I just re-read through this thread. It seems the main thing is we don't want to automatically pull the security token because it can be wrong sometimes. However, other users of Lambda rely on pulling the security token. Does anyone have a link to documentation about why there are competing use-cases? We can add another storage or a setting once I understand the root problem. |
thanks , it work for me |
i was able to fix by adding custom storages.py from django.conf import settings
from storages.backends.s3boto3 import S3Boto3Storage
class SecurityTokenWorkaroundS3Boto3Storage(S3Boto3Storage):
def _get_security_token(self):
return None
class MediaStorage(SecurityTokenWorkaroundS3Boto3Storage):
location = settings.MEDIAFILES_LOCATION
class StaticStorage(SecurityTokenWorkaroundS3Boto3Storage):
location = settings.STATICFILES_LOCATION |
I found this to be a policy issue within AWS. I erased my original policy, recreated it with the policy generator, then pasted. Seemed to do the trick for me. Also the setting |
The above solution won't work anymore as For example: STORAGES = {
"staticfiles": {
"BACKEND": "storages.backends.s3.S3Storage",
"OPTIONS": {
"access_key": ENV("APP_S3_ACCESS_KEY"),
"secret_key": ENV("APP_S3_SECRET_KEY"),
"bucket_name": ENV("APP_S3_BUCKET_NAME"),
},
},
} |
When I save in local it keeps me well in S3 but when it is running with lamda I get the following error.
`
`
The text was updated successfully, but these errors were encountered: