python - 将安全组设置为 ALB aws
问题描述
我正在尝试为我的 ALB 设置一些安全组。这是我写的代码:
def set_alb_security_group(cfd_sg):
global ALB_ARN
client = boto3.client('elb', 'eu-central-1')
result = client.apply_security_groups_to_load_balancer(
LoadBalancerName='Jenkins-ELB',
SecurityGroups=['sg-088257e3c09954802', 'sg-0f99e3a27f7ceb393', 'sg-0c262b4c866c7258a']
)
logging.info(result)
不幸的是,它不起作用,这是我得到的代码:
{
"errorMessage": "An error occurred (LoadBalancerNotFound) when calling the ApplySecurityGroupsToLoadBalancer operation: There is no ACTIVE Load Balancer named 'Jenkins-ELB'",
"errorType": "AccessPointNotFoundException",
"stackTrace": [
" File \"/var/task/lambda.py\", line 44, in lambda_handler\n update_security_groups(cf_ranges)\n",
" File \"/var/task/lambda.py\", line 58, in update_security_groups\n rangeToUpdate = get_security_groups_for_update(client, True)\n",
" File \"/var/task/lambda.py\", line 245, in get_security_groups_for_update\n return create_security_groups(client, response)\n",
" File \"/var/task/lambda.py\", line 227, in create_security_groups\n set_alb_security_group(created_sgs)\n",
" File \"/var/task/lambda.py\", line 279, in set_alb_security_group\n result = client.apply_security_groups_to_load_balancer(\n",
" File \"/var/runtime/botocore/client.py\", line 386, in _api_call\n return self._make_api_call(operation_name, kwargs)\n",
" File \"/var/runtime/botocore/client.py\", line 705, in _make_api_call\n raise error_class(parsed_response, operation_name)\n"
]
}
我 100% 确定我拥有与此名称完全相同的负载均衡器。我在这里做错了什么?谢谢!
解决方案
您的客户端设置为与Classic Load Balancer一起使用,而不是与您elb
用作客户端类型的 Application Load Balancer 一起使用。
client = boto3.client('elb', 'eu-central-1')
文档:
本参考涵盖了支持Classic Load Balancer的 2012-06-01 API
要创建与 Application Load Balancer 一起使用的客户端,您需要提供elbv2
客户端类型:
client = boto3.client('elbv2, 'eu-central-1')
文档:
本参考涵盖以下负载均衡器类型:
Application Load Balancer - 在应用层(第 7 层)运行,支持 HTTP 和 HTTPS。
网络负载均衡器 - 在传输层(第 4 层)运行并支持 TCP、TLS 和 UDP。
网关负载均衡器 - 在网络层(第 3 层)运行。
推荐阅读
- entity-framework-core - 即使属性类型不可为空,是否可以将数据库列配置为允许 NULL?
- javascript - 如何在 JavaScript 中保存网站以供离线使用
- php - PHP:如何下载 gzip 压缩的内容?
- iccube - IcCube 架构加载速度优化
- lambda - 如何在 Kotlin 中将 Lambda 传递给 toSortedSet()
- javascript - 函数有时可以返回一些东西,有时不能吗?
- listview - OnTap 后刷新 Flutter ListView
- hadoop - 云端大数据 (Azure)
- java - 使用 JFileChooser 从不同目录中选择多个文件
- reactjs - 为什么不推荐使用 componentWillReceiveProps?