我想用boto3来读取现货价格。我添加了一个使用iampaws的用户,并为他提供了使用策略
我用awscli在我的UBUNTU机器上配置aws
当我运行简单的例子来获取现货价格时,我有以下错误:
ClientError: An error occurred (OptInRequired) when calling the DescribeSpotPriceHistory operation: You are not subscribed to this service. Please go to http://aws.amazon.com to subscribe.
代码:
import boto3
client = boto3.client(
'ec2',region_name='us-east-1',
aws_access_key_id=ACCESS_KEY,
aws_secret_access_key=SECRET_KEY,
)
prices=client.describe_spot_price_history(InstanceTypes=['m3.medium'],MaxResults=1,ProductDescriptions=['Linux/UNIX (Amazon VPC)'],AvailabilityZone='us-east-1')
print prices['SpotPriceHistory'][0]
嗯,您正在进行的
describe_spot_price_history()
调用有两个问题:AvailabilityZone='us-east-1'
错误。必须指定AZ:us-east-1a
或{us-east-1
。当我尝试的时候,这给了我一个ClientError: ... InvalidParameterValue
。在MaxResults=1
您实际上只会从调用中获得一个数据点,这可能不是非常有用。您必须遍历剩余的页面,以获取剩余的价格历史记录。我不确定是否有任何明确的保证,即检索到的第一个结果始终是此价格历史记录的最新数据点(尤其是因为您没有指定StartTime
或{除了这些问题,这个呼吁应该是有效的。仔细检查您提供的访问密钥、您正在使用的IAM用户的策略,并根据@krishna-kumar-r的评论建议,联系支持部门,以防您的AWS帐户可能拖欠。在
相关问题 更多 >
编程相关推荐