#read only database error - aws lambda

187 messages · Page 1 of 1 (latest)

forest cliff
#

Hey i deployed my project on aws lamda by zappa. it got deployed successfully, but when I try to use a function which have to acces the database I got an error “attempted to use readonly database”

olive ore
#

db setup must be in read mode only

forest cliff
#

Yeah I know that but where to change it or smth

#

I have tried chmod and deploying it again but don’t works still

olive ore
#

I mean it depends

forest cliff
#

How to solve it

olive ore
#

Lambada issue thn

#

Lambda function is unable to write to the database

forest cliff
#

Yes I know what does it mean

#

But still don’t know how to solve it

olive ore
#

I mean it's not my CODE

forest cliff
#

What you need to help me?

lost scaffold
#

What database are you using and how is it hosted? What have you tried to make it not read only?

forest cliff
#

It’s in file, it’s sqlite3

#

In the same folder as the project

#

Locally it works

lost scaffold
#

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?

forest cliff
#

Yes it’s make sense

#

As it’s my first time using aws

#

Bcs my friend said it’s good solution

lost scaffold
#

It is, but there are constraints

forest cliff
#

so i dont know how to host it

lost scaffold
#

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.

forest cliff
#

and then in settings.py just connection credentials as always

lost scaffold
#

Exactly. Your db needs to always be running

olive ore
#

https://railway.app/

more clean and straight forward

Railway

Railway is an infrastructure platform where you can provision infrastructure, develop with that infrastructure locally, and then deploy to the cloud.

forest cliff
forest cliff
forest cliff
olive ore
#

What's wrong with using PostgreSQL

forest cliff
#

migrating all project

#

that why i want to keep the sqlite3

forest cliff
olive ore
#

It's not work like that

#

go through railway doc

#

Its really that SIMPLE...... choose db and connect with your project

forest cliff
#

i filled the credentials

#

but its going to global url

#

instead to the eu-center-1

lost scaffold
#

I don't understand. You'll need to provide more information for someone to help.

forest cliff
#

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

lost scaffold
#

You shouldn't be deleting the database on deploy

forest cliff
#

But on railway

#

Its auto deleting them

lost scaffold
#

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.

forest cliff
#

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?

lost scaffold
#

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.

forest cliff
#

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

lost scaffold
#

Are you using railway to host your app?

forest cliff
#

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

lost scaffold
forest cliff
#

yes i have configured the storages

#

the second option

#

but it still dont have acces to my images

lost scaffold
#

What do you mean?

forest cliff
#

i am using django storages

#

i have filled the

#

with access key

#

and secret

#

etc

#

i have to turn off acl to display this image otherwise access i forbideen

lost scaffold
#

Do you want the ACLs turned on?

#

If so, how are you generating the URLs to your images?

forest cliff
#

brother im newbie to aws

#

i dont know how it should be

lost scaffold
#

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?

forest cliff
#

nope

#

they are showed to all

#

theres no any specific per user

lost scaffold
#

Then set AWS_DEFAULT_ACL to the public-read

forest cliff
#

and shows on the page

#

but now i dont know how to make an upload to it

lost scaffold
#

What have you tried to learn how?

forest cliff
#

and also in the django

#

should be smth wrong

lost scaffold
#

I can't help with the given information

forest cliff
#

i can show a images

#

here

#

i cannot*

#

:/

lost scaffold
#

Yes, that's so people don't paste images of code.

forest cliff
#

i dont want to show code

lost scaffold
#

You can take a screenshot and upload it to an image hosting site

forest cliff
#

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

forest cliff
#

here it is

#

i dont know what to check here

lost scaffold
#

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.

forest cliff
#

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?

lost scaffold
#

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.

forest cliff
#

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

lost scaffold
#

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?

forest cliff
#

oh i have watched the vid

#

i have not setted the policy

#

lemme try

#

maybe thats it

#

oh now i have a django error

forest cliff
#

can i record a vid

#

to show you?

lost scaffold
#

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.

forest cliff
#

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

forest cliff
lost scaffold
#

Does any data get inserted? What about on other models, can you create data there?

Does this flow work locally? Probably worth retrying.

forest cliff
#

it works locally

#

before

#

nothing is inserted

#

to database

#

and nothing to s3

#

just refreshign the page

#

when submiting

#

after few seconds thinking

lost scaffold
#

Is your view setup to render invalid form errors?

forest cliff
#

nope

lost scaffold
#

Then that's probably what's happening.

forest cliff
#

Idk

forest cliff
#

so how you can help me?

lost scaffold
#

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.

forest cliff
#

thats correct

#

everything you writed

lost scaffold
#

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.