Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Ask HN: How would you append to a text file on AWS?
2 points by nexuist on April 24, 2021 | hide | past | favorite | 3 comments
So I was reading through the responses through this question (https://news.ycombinator.com/item?id=26912321) and along the way I circled back to an old pet peeve, which is that it seems like maintaining a simple text file log of anything serverless on AWS is apparently impossible.

Situation: I am running a drawing app over Lambda websockets. I want to have "channels" where a client can post draw commands and everyone sitting in that channel will receive them. Newcomers can request a chat log. Messages will probably come in every few seconds and will be short. Channels are ephemeral so it's unlikely a chat log will ever exceed 1MB.

With EC2, it's just an operating system so you append files locally. However, I don't want to pay for an EC2 instance just to maintain a text file. One option I considered was just hosting an actual IRC server on an EC2 instance, but then I have to figure out how to maintain an IRC network once it grows past one server, which I have no experience in doing.

I thought for sure S3 would have an append function, but it doesn't. The "proper" way to do it is to read the entire file, append the string locally, and then write the result back. This is annoying because it means that every call to log something will exponentially increase the amount of bandwidth required to perform the call. As AWS charges for bandwidth, this is a non-starter.

So the last remaining plan is to use a serverless database like DynamoDB or AWS Aurora. Unfortunately, I'm a college student so a $60/mo price tag for Aurora is actually hefty for me. So DynamoDB it is.

But does it really have to be? Do I really need to spin up an entire database just to store lines of text in the cloud? Don't get me wrong, I know I have to use a database anyways, I just figured there would be something that would already exist that would be easy for this.

Maybe a PubSub startup exists for this type of job? Any recommendations?



Something like this might work: Instead of a single file, write multiple files under an S3 prefix. All keys under that prefix are your "file." Write a lambda to read all the keys under that prefix and set it up through API gateway to return a single "file." You could also write another lambda to periodically merge multiple s3 keys. It might be slow. Dynamo is probably better.


I ran out of space to put it in the original post, but I also wanted to say that I looked at CloudWatch and, while it would be useful as a developer, I don't think it's made for storing user data and it would probably be dumb to try.


How big is the file? You could create a free app on Heroku and just store it in a Postgres database. Make a table, create a new row, and then just concat all the rows. Or you could store it in a Git repo.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: