ERROR: undefined method `aws_access_key' for Chef::Resource::RemoteFile

ERROR: undefined method `aws_access_key' for Chef::Resource::RemoteFile

我想在下面的远程文件配方中使用 AWS S3 存储桶,这样 每当有人在 /tmp/fileA.txt 中更改时。厨师客户端将 运行 以下代码并将 fileA 替换为来自 AWS S3 存储桶的原始 file_Source.txt

remote_file '/tmp/fileA.txt' do
    source 'https://awsS3bucketname/file_Source.txt'
    aws_access_key "mykey"
    aws_secret_key  "mykey"
    action :create
end

但是当我运行在上面的代码中

时,我得到了错误:未定义的方法`aws_access_key'
 [2018-06-20T07:04:25-04:00] ERROR: Running exception handlers
   Running handlers complete
   [2018-06-20T07:04:25-04:00] ERROR: Exception handlers complete
   Chef Client failed. 0 resources updated in 04 seconds
   [2018-06-20T07:04:25-04:00] FATAL: Stacktrace dumped to /tmp/kitchen/cache/chef-stacktrace.out
   [2018-06-20T07:04:25-04:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
   [2018-06-20T07:04:25-04:00] ERROR: undefined method `aws_access_key' for Chef::Resource::RemoteFile
   [2018-06-20T07:04:25-04:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)

remote_file 不支持从 S3 获取文件。您应该查看包含 s3 文件资源的 aws 食谱:

s3_file can be used to download a file from s3 that requires aws authorization. This is a wrapper around the core chef remote_file resource and supports the same resource attributes as remote_file. See remote_file Chef Docs for a complete list of available attributes.

此外,它还添加了属性来处理对 S3 的授权:

Properties:

aws_secret_access_key, aws_access_key and optionally aws_session_token - required, unless using IAM roles for authentication. region - The AWS region containing the file. Default: The current region of the node when running in AWS or us-east-1 if the node is not in AWS.

示例:

aws_s3_file '/tmp/fileA.txt' do
    bucket 'yourbucket'
    remote_path 'file_Source.txt'
    aws_access_key 'mykey'
    aws_secret_access_key 'mykey'
    region 'us-east-1'
    action :create
end

编辑:

您可以将其设置为食谱中 metadata.rb 文件中的依赖项,如下所示:

depends 'aws'

这将使您能够访问本说明书中的自定义资源。