Jets gem really helped me to build AWS Lambda.
It is really helpful for me.
My code writes some data to file and upload to SFTP server.
It seems it is working well since I can see files upload on the SFTP server.
But I can’t find the generated file. I checked in S3 bucket but couldn’t find.
For example, the filename is log/20190927.txt
Could you please help me where those files are located?
Thank you.
filename = "log/#{Time.now.strftime("%Y%m%d")}.txt"
open(filename, 'a') do |f|
f.puts "name"
end
I am using net-sftp gem to upload this generated file to specific SFTP server like this.
Net::SFTP.start(ENV['HOST_1'], ENV['USERNAME_1'], {
:password => ENV['PASSWORD_1'],
:port => ENV['PORT_1'],
:verbose => :debug,
}) do |sftp|
sftp.upload!(filename, "upload/1.log")
end
I can check if files were uploaded on the sftp server so it seems it is working properly.
I am going to find where the generated file is in my project. But I couldn’t find.
Looks like the first code snippet generates a filename and writes it and so it should be there…
"log/#{Time.now.strftime("%Y%m%d")}.txt"
Worked fine here:
test.rb:
require "fileutils"
filename = "log/#{Time.now.strftime("%Y%m%d")}.txt"
FileUtils.mkdir_p(File.dirname(filename))
open(filename, 'a') do |f|
f.puts "name"
end
Bash terminal output:
$ ruby a.rb
$ cat log/20190927.txt
name
$
FYI, if you end up having to generate files on lambda, you will have to write the files to /tmp. The project directory on lambda is a read-only filesystem.
You can download any of those files. They are in the s3 bucket associated with the parent CloudFormation stack that Jets created.
However, you won’t find the generated file you’re creating. That generated file is created as part Lambda running the function. It’ll be in /tmp because that’s where you’re writing it to. It’s not a part of the package code that you are listing in the screenshot.