How can I write to AWS Lambda local file system?

question

#1

Say that I have some configuration that need to be stored in a YAML file. The configuration can be updated dynamically from Form Input fields. What I want to achieve is to create a YAML file if it doesn’t exist and write into it. I did this part on my localhost but on production I get “RubyError: Errno::EROFS: Read-only file system @ rb_sysopen” error which seems pretty obvious that I can write to Lambda Function local file system.

Is there a way I could solve my above problem? Also if I put my YAML file over S3 and read/write from there then would there be any be any best practice within Jets Docs to that?


#2

No specific hard recommendations here.

The /tmp folder is writable. However, the filesystem is not shared across lambda containers, so you’ll probably be better off using S3 or a database to store and update the YAML.


#3

That said, how can I access S3 buckets within Jets app? Meaning that similar to Rails/Initializers where we set S3 object with credentials. Is there any way in jets where I could set

Aws.config.update({
                    profile: ENV['AWS_PROFILE']
                  })

and then in initializers or when the app is starting, I could do

S3 = Aws::S3::Resource.new

This would help me access S3 anywhere in my app files.


#4

Instead of using long-term AWS access keys, use the Lambda IAM Role. They’re designed for this and will automatically be rotated. Docs here: https://rubyonjets.com/docs/iam-policies/

Also, going through these docs may help you get an better understanding of the Lambda and serverless world : https://rubyonjets.com/docs/


#5

Yes but with https://rubyonjets.com/docs/iam-policies/, how em I suppose read / write objects?