Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

400 Bad Request while pulling instances with amazon

Tags:

boto

Can any body say why I'm getting this error?

I'm getting this while pulling instances after connection to amazon server.

import boto

con = boto.connect_ec2(aws_access_key_id='XXX',aws_secret_access_key='XXX')
con.get_all_instances()

Traceback (most recent call last):

  File "getAllinstanc.py", line 7, in <module>

    reservations = ec2conn.get_all_instances()

  File "c:\jiva\py26\lib\site-packages\boto-2.3.0-py2.6.egg\boto\ec2\connection.py", line 467, in get_all_instances

    [('item', Reservation)], verb='POST')
  File "c:\Jiva\py26\lib\site-packages\boto-2.3.0-py2.6.egg\boto\connection.py", line 896, in get_list

    raise self.ResponseError(response.status, response.reason, body)

boto.exception.EC2ResponseError: EC2ResponseError: 400 Bad Request

<?xml version="1.0" encoding="UTF-8"?>
<Response><Errors><Error><Code>RequestExpired</Code><Message>Request has expired. Timestamp date is 2012-04-09T06:54:53Z</Message></Error></Errors><RequestID>44
08be18-5d2b-420b-af48-e2cb03</RequestID></Response>
like image 540
janu Avatar asked Apr 09 '12 07:04

janu


People also ask

How do I get a response from 400 Bad Request?

Flush Your DNS Corrupted or out-of-date DNS lookup data is another reason why you're seeing an HTTP 400 Bad Request. To fix it, you need to clear your DNS cache. DNS data is stored on the operating system of your device, and not on the browser.

What does it mean 400 bad request?

The HyperText Transfer Protocol (HTTP) 400 Bad Request response status code indicates that the server cannot or will not process the request due to something that is perceived to be a client error (for example, malformed request syntax, invalid request message framing, or deceptive request routing).

What does code 400 mean?

The 400 Bad Request error is an HTTP status code that means that the request you sent to the website server, often something simple like a request to load a web page, was somehow incorrect or corrupted and the server couldn't understand it.


2 Answers

Each request made by boto (or any other AWS client library) is cryptographically signed and has a timestamp associated with it (usually the Date header in the request). The timestamps have to be reasonably close, usually within 15 minutes, of Amazon's idea of the current time. If the timestamp is outside this acceptable window, you will receive an error like this.

So, the short answer is to check the system time on the client machine. It appears to be inaccurate.

like image 197
garnaat Avatar answered Oct 24 '22 09:10

garnaat


There's nice method to test for clock skew described on Amazon's forum.

Type:

wget -S  "https://email.us-east-1.amazonaws.com"

This returns an error, but includes the remote system's time in the Date header. Then compare that with the results of date on your system (assuming it's unix derived).

If your OS happens to be Ubuntu or other Debian variant, you can keep the time current by installing an ntp daemon like this:

sudo apt-get install ntp
like image 35
cbare Avatar answered Oct 24 '22 11:10

cbare