簡體   English   中英

將安全組設置為 ALB aws

[英]Set security groups to an 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% 確定我有這個名字的負載均衡器。 我在這里做錯了什么? 謝謝!

您正在使用“elb”作為客戶端,它僅用於“經典”負載均衡器。 由於您使用的是 ALB,您應該使用“elbv2”作為客戶端

您的客戶端設置為使用Classic Load Balancer而不是 Application Load Balancer,因為您使用elb作為客戶端類型。

client = boto3.client('elb', 'eu-central-1')

文件

此參考涵蓋 2012-06-01 API,它支持Classic Load Balancer


要創建與 Application Load Balancer 一起使用的客戶端,您需要提供elbv2作為客戶端類型

client = boto3.client('elbv2, 'eu-central-1')

文件

此參考涵蓋以下負載平衡器類型:

Application Load Balancer - 在應用層(第 7 層)運行,支持 HTTP 和 HTTPS。

網絡負載均衡器 - 在傳輸層(第 4 層)運行並支持 TCP、TLS 和 UDP。

網關負載均衡器 - 在網絡層(第 3 層)運行。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM