#read only database error - aws lambda
187 messages · Page 1 of 1 (latest)
db setup must be in read mode only
Yeah I know that but where to change it or smth
I have tried chmod and deploying it again but don’t works still
I mean it depends
How to solve it
aaah
Lambada issue thn
Lambda function is unable to write to the database
I mean it's not my CODE
What you need to help me?
What database are you using and how is it hosted? What have you tried to make it not read only?
Aws lamda is an ephemeral hosting option. After each execution, the server is scaled down to nothing. Your application is stateless. This means that your database is being created and destroyed on each request. You need to choose a strategy that allows for persistent data storage. For example, AWS RDS. Or you can switch to running your application on a ec2 instance that you never destroy.
Does that make sense?
Yes it’s make sense
As it’s my first time using aws
Bcs my friend said it’s good solution
It is, but there are constraints
so i dont know how to host it
Fly, heroku, render, platform.sh all try to make it easier. If your set on low cost, then aws is a good choice, but you'll need to do some more research.
and then in settings.py just connection credentials as always
Exactly. Your db needs to always be running
more clean and straight forward
i found this
but theres no anyting for sqlite
What's wrong with using PostgreSQL
i mean rewriting
It's not work like that
go through railway doc
Its really that SIMPLE...... choose db and connect with your project
but i have a little problem
i filled the credentials
but its going to global url
instead to the eu-center-1
I don't understand. You'll need to provide more information for someone to help.
okay i have deploy it
but
i dont know what to do now
bcs sqlite db is keep destroying when pushing new version
how to automate it
to dont destroy or whe nthe deployment is closing bcs new one is coming
sending the sqlite file to another server
but i dont know how to handle this events
You shouldn't be deleting the database on deploy
A quick search makes it seem like railway doesn't support sqlite
You'd need to switch to postgres or mysql
What's happening is what I described earlier with lambda. The db file exists on an ephemeral server that doesn't always exist. So when that server cycles out, all the files are deleted. As I mentioned earlier, you need a persistent place to run your database.
yes i know that now, and thanks again for explanation
but as i searched
its not possible to host the sqlite in the netowrk like mysql
and operate it remotely
only way its exchange between the server and the railway the db.sqlite file
but fro mthat part i dont know how to exchange it with the server
one time
when the server starts
and then when its got closed
you got me now?
No, not really.
You're thinking in the wrong paradigm. You're trying to make everything run on one machine. If you're using something like lambda or railway and need to create/update/delete data, you have to run your database (sqlite, mysql, postgres, redis, etc) on a another machine.
oh okay, but sqlite is not possible to connect to it like mysql
so thats why i dont know how to host if it dont work like a server
Are you using railway to host your app?
okay i have figured out
its on aws
rightn now
and i changed db to postgres
so it works good
but i dont know now how to store static and medias
If you're using AWS, I would recommend using whitenoise for static files and django-storages for the media files.
https://whitenoise.readthedocs.io/en/latest/
https://django-storages.readthedocs.io/en/latest/
yes i have configured the storages
the second option
but it still dont have acces to my images
What do you mean?
i am using django storages
i have filled the
settings in settings.py
with access key
and secret
etc
i have to turn off acl to display this image otherwise access i forbideen
Do you want the ACLs turned on?
If so, how are you generating the URLs to your images?
That's fair, this is difficult. Do you need these images to only be accessible to specific users? For example, are people uploading personal information?
Then set AWS_DEFAULT_ACL to the public-read
yes it is
and shows on the page
but now i dont know how to make an upload to it
What have you tried to learn how?
i think my bucket is not correctly setted up
and also in the django
should be smth wrong
I can't help with the given information
Yes, that's so people don't paste images of code.
i dont want to show code
You can take a screenshot and upload it to an image hosting site
yes i can
but first i want to say
its the problem with permissions
bcs its generating a link to the
files
correctyl
for static its fine
but for uploading it dont work
i have created the user
with s3 full access policy
but still it cannot write into
the s3
only read
here it is
i dont know what to check here
but still it cannot write into
What does this mean? You should try to provide what exactly you're doing and what exactly it is that you're seeing.
becuase in my poject
i need to uplaod a image
so i want to upload it to media
so this action is called writing
and im using django-storages
to make it
it generates the uri to the media
stored
and it shows it only when i public manually this files
and change all acls for everyone access to read
you understand for now?
and it shows it only when i public manually this files
and change all acls for everyone access to read
This part doesn't make sense. Can you elaborate? I feel like your solution is somewhere in this action.
for me its clear
when i upload manually files to s3
i cannot access it from url
but when i change the permissions for the file
everyone access to read
from nothing
it works
just seeing files
but when i change the permissions for the file
There's your solution. You need to make sure the permissions are set correctly when they are uploaded. So what in django-storages have you configured to allow that?
oh i have watched the vid
i have not setted the policy
lemme try
maybe thats it
oh now i have a django error
If you have an error, you shouldn't need to create a video. You have an action and a result.
Videos are hard to search, parse and copy/paste stuff from.
i mean
its not returing any error
but not inserting to database
and also not sending to s3
logo = models.FileField()
this is in my models
it shoudl looks different if i want to send to s3?
Does any data get inserted? What about on other models, can you create data there?
Does this flow work locally? Probably worth retrying.
it works locally
before
nothing is inserted
to database
and nothing to s3
just refreshign the page
when submiting
after few seconds thinking
Is your view setup to render invalid form errors?
nope
Then that's probably what's happening.
Idk
so how you can help me?
At this point I think we're at the end of my help. I think you're close to figuring things out, but I'm not sure. I can't see the code or the errors. When coming across a problem you want help with, you should answer the following three questions:
What did I try?
What did I expect to happen?
What actually happened?
And if the answers are:
I submitted a form with an image.
I expected the image to be uploaded.
The image wasn't uploaded.
It's not enough information. It should be closer to:
I submitted a form with an image. I confirmed that the data and image is being sent via the Network Panel in the developer tools. Here's my view, form, model and template. Here the my media file settings.
What I expected was there to be a row inserted into this table with the value "A" for field "B", and a relative path to with the image's filename on the image column.
What actually happened was that there's no row inserted, the page effectively refreshes, and there is no visible error present. The terminal doesn't show an error either.
Here's my view, form, model and template. Here the my media file settings.
When you ask this question elsewhere, be sure to include the above pieces of information.
At this point I need to step away from our discussion. It sounds like you're on a time crunch, so it's probably a good idea to post this new problem to the proper channel and ask for help from someone else.