sous-chefs / aws

Development repository for the aws cookbook
https://supermarket.chef.io/cookbooks/aws
Apache License 2.0
605 stars 553 forks source link

no implicit conversion of nil into String #182

Closed JustLeo closed 8 years ago

JustLeo commented 8 years ago

Hello, I'm getting the following message error:

TypeError

       no implicit conversion of nil into String
       Cookbook Trace:
       ---------------
       C:\Users\ADMINI~1\AppData\Local\Temp\kitchen\cookbooks\aws\providers\s3_file.rb:34:in 'do_s3_file'
       C:\Users\ADMINI~1\AppData\Local\Temp\kitchen\cookbooks\aws\providers\s3_file.rb:9:in 'block in class_from_file'

so my question is: what are these lines trying to do?

33: obj = ::Aws::S3::Object.new(bucket_name: new_resource.bucket, key: remote_path, client: s3) 34: s3url = obj.presigned_url(:get, expires_in: 300)

filename: s3_file.rb

varun1308 commented 8 years ago

I am facing the same problem. Any workarounds?

meringu commented 8 years ago

I have this issue as well, using log level debug I get

DEBUG: TypeError: aws_s3_file[/var/install] (remote_or_s3_file_test::default line 5) had an error: TypeError: no implicit conversion of nil into String
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.1.35/lib/aws-sdk-core/signers/v4.rb:96:in `+'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.1.35/lib/aws-sdk-core/signers/v4.rb:96:in `signature'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.1.35/lib/aws-sdk-core/signers/v4.rb:79:in `presigned_url'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.1.35/lib/aws-sdk-core/s3/presigner.rb:97:in `block in sign_but_dont_send'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.1.35/lib/aws-sdk-core/plugins/s3_request_signer.rb:149:in `call'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.1.35/lib/aws-sdk-core/xml/error_handler.rb:8:in `call'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.1.35/lib/aws-sdk-core/plugins/s3_request_signer.rb:124:in `call'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.1.35/lib/aws-sdk-core/plugins/s3_redirects.rb:15:in `call'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.1.35/lib/aws-sdk-core/plugins/retry_errors.rb:87:in `call'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.1.35/lib/aws-sdk-core/plugins/s3_md5s.rb:33:in `call'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.1.35/lib/aws-sdk-core/plugins/s3_expect_100_continue.rb:21:in `call'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.1.35/lib/aws-sdk-core/plugins/s3_bucket_dns.rb:31:in `call'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.1.35/lib/aws-sdk-core/rest/handler.rb:7:in `call'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.1.35/lib/aws-sdk-core/plugins/user_agent.rb:12:in `call'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.1.35/lib/seahorse/client/plugins/endpoint.rb:41:in `call'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.1.35/lib/aws-sdk-core/plugins/param_validator.rb:21:in `call'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.1.35/lib/seahorse/client/plugins/raise_response_errors.rb:14:in `call'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.1.35/lib/aws-sdk-core/plugins/s3_sse_cpk.rb:18:in `call'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.1.35/lib/aws-sdk-core/plugins/param_converter.rb:20:in `call'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.1.35/lib/seahorse/client/plugins/response_target.rb:21:in `call'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.1.35/lib/seahorse/client/request.rb:70:in `send_request'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.1.35/lib/aws-sdk-core/s3/presigner.rb:51:in `presigned_url'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/aws-sdk-resources-2.1.35/lib/aws-sdk-resources/services/s3/object.rb:169:in `presigned_url'
/var/chef/cookbooks/aws/providers/s3_file.rb:34:in `do_s3_file'
/var/chef/cookbooks/aws/providers/s3_file.rb:9:in `block in class_from_file'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/provider.rb:362:in `action_create'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/provider.rb:144:in `run_action'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/resource.rb:585:in `run_action'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/runner.rb:49:in `run_action'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/runner.rb:81:in `block (2 levels) in converge'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/runner.rb:81:in `each'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/runner.rb:81:in `block in converge'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/resource_collection/resource_list.rb:83:in `block in execute_each_resource'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/resource_collection/stepable_iterator.rb:116:in `call'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/resource_collection/stepable_iterator.rb:116:in `call_iterator_block'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/resource_collection/stepable_iterator.rb:85:in `step'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/resource_collection/stepable_iterator.rb:104:in `iterate'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/resource_collection/stepable_iterator.rb:55:in `each_with_index'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/resource_collection/resource_list.rb:81:in `execute_each_resource'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/runner.rb:80:in `converge'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/client.rb:653:in `block in converge'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/client.rb:648:in `catch'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/client.rb:648:in `converge'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/client.rb:687:in `converge_and_save'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/client.rb:269:in `run'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/application.rb:270:in `block in fork_chef_client'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/application.rb:258:in `fork'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/application.rb:258:in `fork_chef_client'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/application.rb:224:in `block in run_chef_client'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/local_mode.rb:44:in `with_server_connectivity'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/application.rb:212:in `run_chef_client'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/application/solo.rb:280:in `block in interval_run_chef_client'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/application/solo.rb:269:in `loop'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/application/solo.rb:269:in `interval_run_chef_client'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/application/solo.rb:247:in `run_application'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/application.rb:60:in `run'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/bin/chef-solo:25:in `<top (required)>'
/usr/bin/chef-solo:54:in `load'
/usr/bin/chef-solo:54:in `<main>'

I'm on an EC2 instance with chef solo

$ chef -v
Chef Development Kit Version: 0.10.0
chef-client version: 12.5.1
berks version: 4.0.1
kitchen version: 1.4.2

Here is my recipe

aws_s3_file '/var/install' do
  bucket 'aws-codedeploy-us-east-1'
  remote_path 'latest/install'
end
meringu commented 8 years ago

I found the problem was the EC2 instance had failed to assume the iam role. Having a valid IAM role from the metadata service fixed it.

iennae commented 8 years ago

include_recipe 'aws'

Hey folks,

So the error 'no implicit conversion of nil into String' generally implies that something isn't getting defined that is required.

For S3 you need to have a recipe that looks somewhat like the example from the test cookbook: https://github.com/chef-cookbooks/aws/blob/master/test/fixtures/cookbooks/aws_test/recipes/s3_file.rb

i.e.:

aws_s3_file '/tmp/an_file' do bucket node['aws_test']['bucket'] remote_path node['aws_test']['s3key'] aws_access_key_id node['aws_test']['key_id'] aws_secret_access_key node['aws_test']['access_key'] end

This is also available in the README:

https://github.com/chef-cookbooks/aws/blob/master/README.md

It looks like maybe you aren't defining permissions in your recipe. Going to go ahead and close this. Please reopen if this doesn't fix your issue.

Thanks!