我可以连接到 AWS 区域,但无权获取现货价格

I can connect to an AWS region but am not authorized to get the spot prices

我正在尝试获取 AWS 现货价格历史记录,并且我一直在从本教程中获得帮助:https://medium.com/cloud-uprising/the-data-science-of-aws-spot-pricing-8bed655caed2#.nk3k2m1z0

当我取回连接对象时,我能够连接到给定区域。

但是当我到达以下行时出现错误:

prices = ec2.get_spot_price_history(start_time=start, end_time=end, instance_type=instance)

这是我得到的错误:

will process from 2016-05-26T00:00:00 to 2016-05-26T11:59:59
EC2Connection:ec2.us-east-1.amazonaws.com
Traceback (most recent call last):
  File "test.py", line 30, in <module>
    prices = conn.get_spot_price_history(start_time=start, end_time=end, instance_type=instance_types[0])
  File "/usr/lib/python2.7/dist-packages/boto/ec2/connection.py", line 1420, in get_spot_price_history
    [('item', SpotPriceHistory)], verb='POST')
  File "/usr/lib/python2.7/dist-packages/boto/connection.py", line 1186, in get_list
    raise self.ResponseError(response.status, response.reason, body)
boto.exception.EC2ResponseError: EC2ResponseError: 401 Unauthorized
<?xml version="1.0" encoding="UTF-8"?>
<Response><Errors><Error><Code>AuthFailure</Code><Message>AWS was not able to validate the provided access credentials</Message></Error></Errors><RequestID>70a8b7bd-28e2-4526-83df-d0cb86e1f491</RequestID></Response>

谁能告诉我为什么我可以连接但未获得授权?

您使用的 AWS 凭据没有执行 ec2:DescribeSpotPriceHistory 命令的权限。

要解决此问题:

  1. 转到 IAM 管理控制台
  2. 找到您在连接期间使用的 IAM 用户或角色
  3. 给自己权限执行ec2:DescribeSpotPriceHistory

不要偷懒,给自己管理员权限。做对了,给自己正确的权限。

我想通了。结果我的电脑时间慢了 7 分钟。我在某处读到,除了您的凭据外,AWS 还使用您的 CPU 时间。

基本上我手动改了时间,现在可以了:)