我正在尝试使用厨师从AWS s3桶下载文件(厨师超市提供的aws食谱)。我一直收到以下错误消息。
Net::HTTPServerException
------------------------
remote_file[/etc/chef/encrypted_data_bag_secret] (/var/chef/cache/cookbooks/aws/providers/s3_file.rb line 36) had an error: Net::HTTPServerException: 400 "Bad Request"
出于身份验证的目的,我正在使用IAM角色。我可以使用aws s3命令行下载相同的文件。这意味着角色本身没有问题。
详细日志如下。
Net::HTTPServerException
------------------------
remote_file[/etc/chef/encrypted_data_bag_secret] (/var/chef/cache/cookbooks/aws/providers/s3_file.rb line 36) had an error: Net::HTTPServerException: 400 "Bad Request"
Resource Declaration:
---------------------
# In /var/chef/cache/cookbooks/appservers/recipes/appconfig.rb
3: aws_s3_file "/etc/chef/encrypted_data_bag_secret" do
4: bucket "app-chefconfig"
5: remote_path "encrypted_data_bag_secret"
6: end
Compiled Resource:
------------------
# Declared in /var/chef/cache/cookbooks/appservers/recipes/appconfig.rb:3:in `from_file'
aws_s3_file("/etc/chef/encrypted_data_bag_secret") do
action :create
retries 0
retry_delay 2
default_guard_interpreter :default
path "/etc/chef/encrypted_data_bag_secret"
declared_type :aws_s3_file
cookbook_name "appservers"
recipe_name "appconfig"
bucket "app-chefconfig"
remote_path "encrypted_data_bag_secret"
use_etag true
use_last_modified true
atomic_update true
end
Running handlers:
[2015-10-30T05:04:28+00:00] ERROR: Running exception handlers
Running handlers complete
[2015-10-30T05:04:28+00:00] ERROR: Exception handlers complete
Chef Client failed. 0 resources updated in 02 seconds
[2015-10-30T05:04:28+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
[2015-10-30T05:04:28+00:00] ERROR: aws_s3_file[/etc/chef/encrypted_data_bag_secret] (appservers::sosconfig line 3) had an error: Net::HTTPServerException: remote_file[/etc/chef/encrypted_data_bag_secret] (/var/chef/cache/cookbooks/aws/providers/s3_file.rb line 36) had an error: Net::HTTPServerException: 400 "Bad Request"
[2015-10-30T05:04:28+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
Stacktrace输出:
Generated at 2015-10-30 05:04:28 +0000
Net::HTTPServerException: aws_s3_file[/etc/chef/encrypted_data_bag_secret] (appservers::appconfig line 3) had an error: Net::HTTPServerException: remo
te_file[/etc/chef/encrypted_data_bag_secret] (/var/chef/cache/cookbooks/aws/providers/s3_file.rb line 36) had an error: Net::HTTPServerException: 400
"Bad Request"
/opt/chef/embedded/lib/ruby/2.1.0/net/http/response.rb:119:in `error!'
/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/http.rb:179:in `streaming_request'
/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/provider/remote_file/http.rb:60:in `fetch'
/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/provider/remote_file/content.rb:71:in `grab_file_from_uri'
/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/provider/remote_file/content.rb:56:in `try_multiple_sources'
/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/provider/remote_file/content.rb:41:in `file_for_provider'
/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/file_content_management/content_base.rb:40:in `tempfile'
/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/provider/file.rb:462:in `tempfile'
/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/provider/file.rb:339:in `do_generate_content'
/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/provider/file.rb:150:in `action_create'
/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/provider.rb:144:in `run_action'
/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/resource.rb:585:in `run_action'
/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/runner.rb:49:in `run_action'
/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/runner.rb:81:in `block (2 levels) in converge'
/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/runner.rb:81:in `each'
/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/runner.rb:81:in `block in converge'
/opt/chef/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/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/resource_collection/stepable_iterator.rb:116:in `call'
/opt/chef/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/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/resource_collection/stepable_iterator.rb:85:in `step'
/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/resource_collection/stepable_iterator.rb:104:in `iterate'
/opt/chef/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/chef/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/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/runner.rb:80:in `converge'
/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/provider.rb:363:in `action_create'
/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/provider.rb:144:in `run_action'
/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/resource.rb:585:in `run_action'
/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/runner.rb:49:in `run_action'
/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/runner.rb:81:in `block (2 levels) in converge'
/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/runner.rb:81:in `each'
/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/runner.rb:81:in `block in converge'
/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/client.rb:648:in `catch'
/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/client.rb:648:in `converge'
/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/client.rb:687:in `converge_and_save'
/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/client.rb:269:in `run'
/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/application.rb:270:in `block in fork_chef_client'
/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/application.rb:258:in `fork'
/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/application.rb:258:in `fork_chef_client'
/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/application.rb:224:in `block in run_chef_client'
/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/local_mode.rb:44:in `with_server_connectivity'
/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/application.rb:212:in `run_chef_client'
/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/application/client.rb:408:in `block in interval_run_chef_client'
/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/application/client.rb:398:in `loop'
/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/application/client.rb:398:in `interval_run_chef_client'
/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/application/client.rb:388:in `run_application'
/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/application.rb:60:in `run'
/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/bin/chef-client:26:in `<top (required)>'
/usr/bin/chef-client:54:in `load'
/usr/bin/chef-client:54:in `<main>'
答案 0 :(得分:0)
aws_s3_file
可能存在一些错误。我写了下面的方法来解决这个问题。
include_recipe 'aws'
require 'aws-sdk'
client = Aws::S3::Client.new(region: 'us-east-1')
bucket = client.get_object(bucket:'app-chefconfig', key: 'encrypted_data_bag_secret')
# Read content to variable
file_content = bucket.body.read
# Log output (optional)
Chef::Log.info(file_content)
# Write content to file
file '/etc/chef/encrypted_data_bag_secret' do
owner 'root'
group 'root'
mode '0755'
content file_content
action :create
end