【问题标题】:ERROR: undefined method `aws_access_key' for Chef::Resource::RemoteFile错误:Chef::Resource::RemoteFile 的未定义方法“aws_access_key”
【发布时间】:2018-06-20 21:01:16
【问题描述】:

我想在下面的远程文件配方中使用 AWS S3 存储桶,这样 每当有人更改 /tmp/fileA.txt。 chef 客户端将运行以下代码并将 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

但是当我运行上面的代码时,我得到 ERROR: undefined method `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)

【问题讨论】:

    标签: chef-infra chef-recipe


    【解决方案1】:

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

    s3_file 可用于从 s3 下载需要 aws 的文件 授权。这是核心主厨 remote_file 的包装 资源并支持与remote_file 相同的资源属性。看 remote_file Chef Docs 获取可用属性的完整列表。

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

    属性:

    aws_secret_access_keyaws_access_key 和可选 aws_session_token - 必需,除非使用 IAM 角色 验证。 region - 包含文件的 AWS 区域。默认: 在 AWS 或 us-east-1 中运行时节点的当前区域(如果 节点不在 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'
    

    这将使您能够访问本食谱中的自定义资源。

    【讨论】:

    • 错误:没有名为“aws_s3_file”的资源或方法
    • 您是否将该说明书添加为依赖项?
    • 依赖是什么意思?我的食谱中有许多食谱,我通过传递所有食谱名称使用 default.rb 运行所有这些食谱。
    • yesi 在 metadata.rb 中添加了依赖,但仍然存在错误:未定义方法 `aws_secret_key' 用于来自食谱 aws 的自定义资源 aws_s3_file
    • 抱歉@PawanSharma 看到正确答案应该是aws_secret_access_keyaws_access_key
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-12
    • 1970-01-01
    • 2015-12-25
    • 1970-01-01
    • 1970-01-01
    • 2018-09-02
    相关资源
    最近更新 更多