Search code examples
pythonamazon-web-servicesamazon-ec2botounauthorized

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


I am trying to get AWS spot price history and I have been getting help from this tutorial: https://medium.com/cloud-uprising/the-data-science-of-aws-spot-pricing-8bed655caed2#.nk3k2m1z0

I am able to connect to the given region as I get back the connection object.

But I get an error when I reach the following line:

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

This is the error I get:

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>

Can anyone tell my how is it possible that i can connect but am not authorized?


Solution

  • I figured out the problem. It turns out my pc time was 7 minutes slower. and I read somewhere that AWS in addition to your credentials also uses your CPU time.

    Basically I manually changed the time, and now it works:)