使用 Chef 配置在 AWS 中创建负载均衡器

Creating load balancer in AWS using Chef provisioning

我正在尝试在 AWS 中创建负载均衡器。我已经创建了机器并且机器的节点文件在我的节点文件夹中。我不断收到错误消息,要求我输入机器的实例 ID。我认为使用 chef provisioning 的全部意义在于能够使用机器的名称来使用它,而不必使用它的实例 ID。我的代码如下:

require 'chef/provisioning'  # driver for creating machines

provisioner = get_setting("CHEF_PROFILE", "abcd-environments")

require "chef/provisioning/aws_driver"

with_driver "aws:abcd-environments"

load_balancer 'test-elb-from-prov' do

  driver "aws:abcd-environments"
  machines ['webappsadm001.da.abcd']
  load_balancer_options   availability_zones: ['us-east-1b'],
  listeners: [{
    # required
    protocol: :http,
    # required
    port: 80,
    instance_protocol: :http,
    # required
    instance_port: 10262,
    }],
  subnets: ['subnet-37ce3a1c'],

    health_check:
    [{
      target: "TCP:10262",
      interval: 30,
      timeout: 5,
      unhealthy_threshold: 2,
      healthy_threshold: 10
    }]

end

日志如下:

 ================================================================================
    Error executing action `create` on resource 'load_balancer[test-elb-from-prov]'
    ================================================================================

    AWS::Core::OptionGrammar::FormatError
    -------------------------------------
    expected string value for key instance_id of member 1 of option instances

如果该机器是您的节点文件夹中的现有节点,您应该能够为该现有机器定义一个资源,使用操作 :nothing,然后引用它。

因此,如果节点名称是 'myinstance',配方将如下所示:

machine 'myinstance' do
  action :nothing
end

load_balancer 'my_load_balancer' do
  machines ['myinstance']
end

所以我想出了问题。我通过另一本食谱使用 aws fog 驱动程序创建了机器。

然后我尝试将负载平衡器附加到机器上。当它试图查看节点的 JSON 文件时,它的格式不同,因此出错。

我删除了机器和 运行 食谱。这使用 aws 驱动程序创建了机器,并按预期创建和连接了负载均衡器。