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

Invalid type for parameter Filters[0] when filtering for tags #108

Open
drksnw opened this issue Jun 8, 2020 · 12 comments · May be fixed by #109
Open

Invalid type for parameter Filters[0] when filtering for tags #108

drksnw opened this issue Jun 8, 2020 · 12 comments · May be fixed by #109

Comments

@drksnw
Copy link

drksnw commented Jun 8, 2020

Hello,

I have a problem with the ec2_describe_instances action.

Calling the action without any filter works well, however I would need to only get instances with a specific tag.

I tried adding the Filters parameter like this : Filters=tag:Name=test-instance however, it crashes at botocore as it need to have a dict instead of a string.

I've also tried to write the filter like a dict (with { and }), but it seems that the parameter is always casted to a string, which breaks the functionality.

Here is the full stack trace :

st2.actions.python.ActionManager: DEBUG    Calling method "boto3.ec2.describe_instances" with kwargs: {u'Filters': [u'tag:Name=test-instance']}
Traceback (most recent call last):
  File "/opt/stackstorm/st2/lib/python2.7/site-packages/python_runner/python_action_wrapper.py", line 333, in <module>
    obj.run()
  File "/opt/stackstorm/st2/lib/python2.7/site-packages/python_runner/python_action_wrapper.py", line 192, in run
    output = action.run(**self._parameters)
  File "/opt/stackstorm/packs/aws/actions/run.py", line 36, in run
    return self.do_method(module_path, cls, aws_action, **kwargs)
  File "/opt/stackstorm/packs/aws/actions/lib/action.py", line 226, in do_method
    resultset = getattr(obj, action)(**kwargs)
  File "/opt/stackstorm/virtualenvs/aws/lib/python2.7/site-packages/botocore/client.py", line 251, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/opt/stackstorm/virtualenvs/aws/lib/python2.7/site-packages/botocore/client.py", line 513, in _make_api_call
    api_params, operation_model, context=request_context)
  File "/opt/stackstorm/virtualenvs/aws/lib/python2.7/site-packages/botocore/client.py", line 566, in _convert_to_request_dict
    api_params, operation_model)
  File "/opt/stackstorm/virtualenvs/aws/lib/python2.7/site-packages/botocore/validate.py", line 270, in serialize_to_request
    raise ParamValidationError(report=report.generate_report())
botocore.exceptions.ParamValidationError: Parameter validation failed:
Invalid type for parameter Filters[0], value: tag:Name=test-instance, type: <type 'unicode'>, valid types: <type 'dict'>

Do you know if I'm using the Filters parameter wrong, or is there any other problem ?

Thanks in advance for your help !

Best regards

@winem
Copy link

winem commented Jun 8, 2020

Hi,

try it like this:
ec2_client.describe_instances(Filters=[{'Name': 'tag:Key', 'Values': [ test-instance ]})

This will return all instances with a tag test-instance regardless of the value. If you want to check for a specific value the query would look like this: (Filters=[{'Name': 'tag:test-instance', 'Values': [ <the-value-you-are-looking-for> ]}).

Cheers,
Marcel

@drksnw
Copy link
Author

drksnw commented Jun 8, 2020

Hi @winem,
Thanks for your quick reply.

It seems that it doesn't work either with this syntax, now I have these error messages :

Invalid type for parameter Filters[0], value: Name:tag:Key, type: <type 'unicode'>, valid types: <type 'dict'>
Invalid type for parameter Filters[1], value: Values:[test-instance], type: <type 'unicode'>, valid types: <type 'dict'>

I'm trying to call it directly with st2 run, maybe have I to use a different syntax ?

The command I'm running is the following :

st2 run aws.ec2_describe_instances Filters={'Name':'tag:Key','Values':[test-instance]} account_id=xxxxxxxxxxxx region=eu-central-1

Thanks !

Best regards

@winem
Copy link

winem commented Jun 8, 2020

Hi, can't test it right now but as far as I remember Filters need to be an array, too. So wrap the filter in [] please -> [{'Name':'tag:Key','Values':[test-instance]}]

If that's not working either I'll try to find some time test it later today.

@drksnw
Copy link
Author

drksnw commented Jun 8, 2020

Hi,
Mmh, still not :

botocore.exceptions.ParamValidationError: Parameter validation failed:
Invalid type for parameter Filters[0], value: [Name:tag:Key], type: <type 'unicode'>, valid types: <type 'dict'>
Invalid type for parameter Filters[1], value: [Values:[test-instance]], type: <type 'unicode'>, valid types: <type 'dict'>

I will try to dig deeper in the code too, maybe I will find something interesting.

Thanks for your help !

@winem
Copy link

winem commented Jun 8, 2020

Please post your current filter again. Is it {'Name':'tag:Key'],['Values':[test-instance]]} now?

@drksnw
Copy link
Author

drksnw commented Jun 8, 2020

My filter is : [{'Name':'tag:Key','Values':[test-instance]}]

@drksnw
Copy link
Author

drksnw commented Jun 8, 2020

Ok, I've found out what's wrong.

I have modified the action.py script in order to get the filters in an user-friendlier way (like Filters=Key1=Value1,Key2=Value2...)

I will edit it in order to have multiples values for a key, and I will do a pull request.

Best regards

@satellite-no
Copy link
Contributor

Has this gone anywhere? What is the current way to implement filters or is this just simply broke?

I've tried every way I can think of.

st2 run aws.ec2_describe_instances Filters=instance-state-name=running
st2 run aws.ec2_describe_instances Filters='instance-state-name'='running'
st2 run aws.ec2_describe_instances Filters="{instance-state-name='running'}"
st2 run aws.ec2_describe_instances Filters={instance-state-name='running'}
st2 run aws.ec2_describe_instances Filters={instance-state-name=running}
st2 run aws.ec2_describe_instances Filters=[{'Name': 'instance-state-name', 'Values': 'running'}]
st2 run aws.ec2_describe_instances Filters=[{'Name':'instance-state-name','Values':'running'}]
st2 run aws.ec2_describe_instances Filters={Name:'instance-state-name',Values:'running'}

@amanda11
Copy link
Contributor

I think Values is an array. I'm not using AWS pack, but the AWS_boto3 pack, and with that I have:

    action: aws_boto3.boto3action
    input:
      action_name: describe_instances
      service: ec2
      params: 
        Filters: 
          - Name: instance-state-name
            Values: 
              - running

So that would imply that you might want to try:
st2 run aws.ec2_describe_instances Filters=[{'Name':'instance-state-name','Values':['running']}]

@satellite-no
Copy link
Contributor

Hey @amanda11,
Thanks for the suggestion, looks like that gives the same errors as the others. I'm really thinking this action is just bugged.

botocore.exceptions.ParamValidationError: Parameter validation failed:
Invalid type for parameter Filters[0], value: [Name:instance-state-name], type: <class 'str'>, valid types: <class 'dict'>
Invalid type for parameter Filters[1], value: [Values:[running]], type: <class 'str'>, valid types: <class 'dict'>

@cwilson21
Copy link

Has anyone poked further at this? I am running into the same issue when trying to use ec2_describe_instances where the filter is right however it is still throwing a validation error @drksnw ?

@cwilson21
Copy link

So just for the record here. I got this to work.... The problem being the single quotes. The filter I used looked sort of like this:

[{"Name":"tag:Name","Values":["value"]}]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants