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

Added the ability to pass in args and kwargs to the zappa invoke #983

Closed
wants to merge 0 commits into from

Conversation

xuru
Copy link

@xuru xuru commented Jul 3, 2017

Description

Added the ability to pass in arguments to invoked commands from the command line. For example:

$ zappa invoke production 'my_app.my_function' one two three=3 name=bob

Which would get passed to your function in the event['args'] and event['kwargs'] dictionary. For example:

def myfunc(event, context):
    print("Args: {}".format(event['args']))
    print("Kwargs: {}".format(event['kwargs']))

Would print out

Args: ['one', 'two']
Kwargs: {'three': '3', 'name': 'bob'}

GitHub Issues

Couldn't find a ticket for this, but @Miserlou said in slack:

this was assigned to somebody as their school project but they never did it

@coveralls
Copy link

coveralls commented Jul 3, 2017

Coverage Status

Coverage decreased (-22.3%) to 50.995% when pulling 8012c9d on xuru:master into b7c16d3 on Miserlou:master.

@Miserlou
Copy link
Owner

Miserlou commented Jul 3, 2017

The build is not happy!

@coveralls
Copy link

coveralls commented Jul 5, 2017

Coverage Status

Coverage decreased (-0.2%) to 73.118% when pulling 1955890 on xuru:master into b7c16d3 on Miserlou:master.

@coveralls
Copy link

coveralls commented Jul 5, 2017

Coverage Status

Coverage decreased (-0.2%) to 73.118% when pulling 1955890 on xuru:master into b7c16d3 on Miserlou:master.

zappa/handler.py Outdated
@@ -336,9 +336,27 @@ def handler(self, event, context):

# This is a direct command invocation.
elif event.get('command', None):
if not event['command']:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is entirely redundant with the previous line.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 338 checks for the existence of the key/value of 'command in the dictionary, but doesn't check if that value is a "false" value (None, empty string, etc).

Copy link
Contributor

@pjz pjz Jul 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if command is a valid key, thenevent.get('command') is the same as event['command'], so it is a check for falsity, with a side effect of returning None instead of throwing KeyError

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, you are correct, sorry, got my mind on other things...

@coveralls
Copy link

coveralls commented Jul 7, 2017

Coverage Status

Coverage decreased (-0.2%) to 73.307% when pulling b039d54 on xuru:master into d3a986e on Miserlou:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) to 73.307% when pulling b039d54 on xuru:master into d3a986e on Miserlou:master.

@Miserlou
Copy link
Owner

I'd still like to see this merged! @Mizell - can you review and test it for your purposes?

@smizell
Copy link

smizell commented Aug 24, 2017

@Miserlou I'll test it out either today or tomorrow. This is great!

zappa/handler.py Outdated
whole_function = event['command']
args = []
kwargs = {}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'd recommend not going the non-standard way of parsing command line keyword arguments. For most command lines, I'd expect something like zappa invoke "myapp.myfunc" arg1 arg2 --arg3 foo to provide args as ['arg1', 'arg2'] and kwargs as {'arg3': 'foo'}.

Of course this is up to you @xuru and @Miserlou, but I think leaving out kwargs for the first iteration would be best.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, i've been pretty busy and couldn't get back to this. I do have a ticket this sprint to get back to this, so I can help out tomorrow or this weekend. That said, here is where I left off: I wasn't able to get this working, and I don't really remember what the issue was. I'll take a look and let you know when I can.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xuru no worries! And thank you for working on this. I'm going to tinker with it probably tomorrow as well.

@johnyoonh
Copy link

Could you please reopen this?
Running v0.47. Reproduced it in v0.46
 zappa invoke staging "tilda.tasks.delete_task" k
usage: zappa [-h] [-v] [--color {auto,never,always}]
{certify,deploy,init,package,template,invoke,manage,rollback,schedule,status,tail,undeploy,unschedule,update,shell}
...
zappa: error: unrecognized arguments: k
[1] 45852 exit 2 zappa invoke staging "tilda.tasks.delete_task" k

@pjz
Copy link
Contributor

pjz commented Oct 24, 2018

I'd think it needs to be opened as a bug, not re-opened the original feature creation.

@xoelop
Copy link

xoelop commented Jul 17, 2019

I'm having the same problem, can't send args or kwargs to functions using zappa invoke. Any progress on this? Thanks!!

@Giribhushan
Copy link

I also have same problem. Did anyone fix this ?

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 this pull request may close these issues.

None yet

8 participants