AttributeError:“ElasticLoadBalancingv2”对象没有“设置所需容量”属性

2024-06-17 12:48:30 发布

您现在位置:Python中文网/ 问答频道 /正文

import boto3
import json
import time
client = boto3.client('elbv2')
desired_capacity=8
client.set_desired_capacity(
    AutoScalingGroupName='Test-Web',
    DesiredCapacity=desired_capacity,
    HonorCooldown=True)

及 boto3==1.7.1

当我运行这个脚本时,我得到一个

  File "deploy_staging_web.py", line 6, in <module>
    client.set_desired_capacity(
  File "/usr/local/lib/python2.7/dist-packages/botocore/client.py", line 601, in __getattr__
    self.__class__.__name__, item)
AttributeError: 'ElasticLoadBalancingv2' object has no attribute 'set_desired_capacity'

我打算使用python来上下扩展aws实例

我现在不在任何虚拟环境中

为什么它会被扔出去,我该如何穿过它? 这里甚至在官方文件中提到:https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/autoscaling.html#AutoScaling.Client.set_desired_capacity

enter image description here


Tags: inpytestimportclientjsontimeline
2条回答

这个问题原来是个愚蠢的问题。
boto3已围绕各种功能移动

设置所需容量不再是“elbv2”的一部分。
它是“自动缩放”https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/autoscaling.html#AutoScaling.Client.set_desired_capacity的一部分

虽然“描述目标健康”仍然是前者的一部分

更新

client = boto3.client('elbv2')

client = boto3.client('autoscaling')

解决了我的问题

官方文件是最新版本的,不是你的太旧的版本。将boto3包升级至最新版本。最新版本是1.9.243

相关问题 更多 >