amazon-web-services - 向 Application Load Balancer (ALB) 注册 EC2 实例时出现问题
问题描述
根据文档,我应该能够使用elb_instance模块注册 EC2 实例,但播放失败并显示ELB Staging1 does not exist
. 对于健全性检查,我尝试使用 AWS CLI 工具,但使用An error occurred (LoadBalancerNotFound) when calling the RegisterInstancesWithLoadBalancer operation: There is no ACTIVE Load Balancer named 'Staging1'
. 作为情节转折:
- AWS 控制台将 ALB 显示为“活动”
elb_application_lb_facts
也列出来ec2_elb_facts
没有列出它(它只列出了我拥有的经典 ELB)
似乎应用程序负载均衡器仅在较新的 api 版本中受支持,并且模块或 cli 不适合使用它。但是我找不到明确提到它们不应该工作。我也知道elbv2
command,但它似乎没有提供将实例注册到 ELB 的方法。
我在这里想念什么?
我写的 Ansible 任务:
- name: Register instances in the ALB
local_action:
module: elb_instance
aws_access_key: "{{ aws_credentials.access_key_id }}"
aws_secret_key: "{{ aws_credentials.secret_access_key }}"
region: "{{ aws_region }}"
instance_id: "{{ item.instance_ids.0 }}"
ec2_elbs: "Staging1"
state: present
wait: yes
loop: "{{ new_instances.results }}"
使用 cli 工具替代aws
(也不起作用):
- name: Register instance in ALB workaround
command: "aws elb register-instances-with-load-balancer --load-balancer-name Staging1 --instances {{ instance_ids | join(' ') }}"
environment:
AWS_REGION: "{{ aws_region }}"
AWS_ACCESS_KEY: "{{ aws_credentials.access_key_id }}"
AWS_SECRET_KEY: "{{ aws_credentials.secret_access_key }}"
解决方案
elbv2 确实提供了一种将目标注册到 elb 的方法。你这样做:
- 创建目标组
- 然后使用注册目标组API 注册您的 EC2 实例
- 然后使用Create Listener API 将 ELB 与目标组关联
在我提供的链接中有这样做的例子。
推荐阅读
- javascript - jQuery 从字符串中提取完成部分域(.com、.it、.fr)
- c# - 编辑器中未发生的构建中的 Unity 错误
- python - Python 在给定时间启动函数:使用 time.sleep()
- javascript - Express:下载返回空文件
- reactjs - 如何以很少的性能损失包装 React 组件?
- javascript - Java:未调用文本字段onkeydown上if-else条件下的Javascript方法
- javascript - 删除类型脚本中的 Json Key
- c# - 从 xamarin 调用文件上传服务不起作用
- php - php mysql join 查询别名
- html - 正确划分每个图像的图像和文本