Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ec2 InstanceExists waiter throws an exception immediately if the instance does not exist #906

Closed
nicholasbishop opened this issue May 3, 2016 · 1 comment · Fixed by #917
Labels
bug This issue is a confirmed bug.

Comments

@nicholasbishop
Copy link
Contributor

Code that reproduces the issue:

import boto3
import botocore

print('boto3 version:', boto3.__version__)
print('botocore version:', botocore.__version__)

# This is an instance that does not exist
invalid_instance_id = 'i-12345678'

ec2_client = boto3.client('ec2')
waiter = ec2_client.get_waiter('instance_exists')
waiter.wait(InstanceIds=[invalid_instance_id])

(Note that although this is an artificial example with an obviously-fake instance ID, the issue also reproduces occasionally with real instances if the waiter is called immediately after creating the instance.)

Output:

$ python3 repro.py 
boto3 version: 1.3.1
botocore version: 1.4.15
Traceback (most recent call last):
  File "repro.py", line 12, in <module>
    waiter.wait(InstanceIds=[invalid_instance_id])
  File "/usr/lib/python3.4/site-packages/botocore/waiter.py", line 53, in wait
    Waiter.wait(self, **kwargs)
  File "/usr/lib/python3.4/site-packages/botocore/waiter.py", line 292, in wait
    if acceptor.matcher_func(response):
  File "/usr/lib/python3.4/site-packages/botocore/waiter.py", line 194, in acceptor_matches
    return expression.search(response) == expected
  File "/usr/lib/python3.4/site-packages/jmespath/parser.py", line 524, in search
    result = interpreter.visit(self.parsed, value)
  File "/usr/lib/python3.4/site-packages/jmespath/visitor.py", line 66, in visit
    return method(node, *args, **kwargs)
  File "/usr/lib/python3.4/site-packages/jmespath/visitor.py", line 114, in visit_comparator
    self.visit(node['children'][0], value),
  File "/usr/lib/python3.4/site-packages/jmespath/visitor.py", line 66, in visit
    return method(node, *args, **kwargs)
  File "/usr/lib/python3.4/site-packages/jmespath/visitor.py", line 129, in visit_function_expression
    return self._functions.call_function(node['value'], resolved_args)
  File "/usr/lib/python3.4/site-packages/jmespath/functions.py", line 89, in call_function
    self._validate_arguments(resolved_args, signature, function_name)
  File "/usr/lib/python3.4/site-packages/jmespath/functions.py", line 100, in _validate_arguments
    return self._type_check(args, signature, function_name)
  File "/usr/lib/python3.4/site-packages/jmespath/functions.py", line 107, in _type_check
    function_name)
  File "/usr/lib/python3.4/site-packages/jmespath/functions.py", line 122, in _type_check_single
    self._convert_to_jmespath_type(actual_typename), types)
jmespath.exceptions.JMESPathTypeError: In function length(), invalid type for value: None, expected one of: ['string', 'array', 'object'], received: "null"

Partial debug logging output (I wasn't sure if the log output could contain sensitive info, hopefully this portion is sufficient):

DEBUG:botocore.endpoint:Sending http request: <PreparedRequest [POST]>
INFO:botocore.vendored.requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): ec2.us-east-1.amazonaws.com
DEBUG:botocore.vendored.requests.packages.urllib3.connectionpool:"POST / HTTP/1.1" 400 None
DEBUG:botocore.parsers:Response headers: {'nncoection': 'close', 'transfer-encoding': 'chunked', 'date': 'Tue, 03 May 2016 04:53:17 GMT', 'server': 'AmazonEC2'}
DEBUG:botocore.parsers:Response body:
b'<?xml version="1.0" encoding="UTF-8"?>\n<Response><Errors><Error><Code>InvalidInstanceID.NotFound</Code><Message>The instance ID \'i-12345678\' does not exist</Message></Error></Errors><RequestID>67ae3003-e224-4a9e-b429-3d6b4d19ec6f</RequestID></Response>'

I believe the problem is in this acceptor: https://github.com/boto/botocore/blob/develop/botocore/data/ec2/2015-10-01/waiters-2.json#L9

It was changed in 23fd477#diff-7c69e2e0de75f54556bb554dea557950; it used to only look at the response status rather than the response body.

Reverting that change to the JSON fixes the problem in my environment.

@jamesls
Copy link
Member

jamesls commented May 12, 2016

Confirmed bug. Taking a look at your PR now.

@jamesls jamesls added the bug This issue is a confirmed bug. label May 12, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a confirmed bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants