I'm working through the tutorial in announcing-ruby-support-for-aws-lambda and I'm having trouble getting Lambda to locate Ruby dependencies.
I've got the tutorial's code just copy/pasted in there. Nothing fancy so far.
require 'aws-record'
class DemoTable
include Aws::Record
set_table_name ENV[‘DDB_TABLE’]
string_attr :id, hash_key: true
string_attr :body
end
def put_item(event:,context:)
body = event["body"]
item = DemoTable.new(id: SecureRandom.uuid, body: body)
item.save! # raise an exception if save fails
item.to_h
end
I've got a Gemfile that contains aws-record and I've run both bundle install and bundle install --deployment.
If I'm in the Lambda console, looking at the Function Code section, I can see the project has the vendor directory and the aws-record gem is present.
I've used the sam CLI to package and deploy the code and it seems like everything worked.
But when I create and run the test, I receive the following error.
{
"errorMessage": "cannot load such file -- aws-record",
"errorType": "Init<LoadError>",
"stackTrace": [
"/var/lang/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'",
"/var/lang/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'",
"/var/task/hello_ruby_record.rb:1:in `<top (required)>'",
"/var/lang/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'",
"/var/lang/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'"
]
}
Everything seems to simple at this stage of the app, so I'm mystified about what I'm missing. Does anyone have any suggestions about how to troubleshoot this?