user664833
user664833

Reputation: 19495

ArgumentError: missing required option :key

I am trying to get an object from an S3 bucket via:

s3 = Aws::S3::Resource.new(
    region: ENV['AWS_REGION'],
    access_key_id: ENV['AWS_ACCESS_KEY_ID'],
    secret_access_key: ENV['AWS_SECRET_ACCESS_KEY']
)

obj = s3.bucket(ENV['AWS_S3_BUCKET_NAME']).object(args[:filename]).get # line causing error

The exact error message is:

ArgumentError: missing required option :key

Upvotes: 1

Views: 1662

Answers (1)

user664833
user664833

Reputation: 19495

The error message could be improved, but it means:

ArgumentError: missing required parameter :key

("Parameters" and "arguments" are quite synonymous, and "options" sometimes get thrown into the mix, but a "required option" is confusing.)

I was refactoring some code and did not notice that args[:filename] was no longer being used... the args Hash was being used, but the :filename symbol was not, so it was returning nil:

> x = {}
 => {} 
> x.class
 => Hash 
> x[:blah]
 => nil 

It worked once I updated the argument/parameter/option name (args[:filename]) to what was being used in the newly refactored source code.

By the way, here's the line in the SDK that the error is coming from.

Upvotes: 1

Related Questions