Min-ops / cruddy

A simple CRUD wrapper around Amazon DynamoDB
Apache License 2.0
24 stars 8 forks source link

Fail gracefully when the Lambda func doesn't have the right permissions #22

Open pas256 opened 8 years ago

pas256 commented 8 years ago

I just did a

./cruddy search my_id=72538

and received the following stacktrace:

error
Traceback (most recent call last):
  File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/Current/bin/cruddy", line 9, in <module>
    load_entry_point('cruddy==0.9.0', 'console_scripts', 'cruddy')()
  File "/usr/local/lib/python2.7/site-packages/click/core.py", line 716, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/click/core.py", line 696, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python2.7/site-packages/click/core.py", line 1060, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python2.7/site-packages/click/core.py", line 889, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python2.7/site-packages/click/core.py", line 534, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/click/decorators.py", line 64, in new_func
    return ctx.invoke(f, obj, *args[1:], **kwargs)
  File "/usr/local/lib/python2.7/site-packages/click/core.py", line 534, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/cruddy/scripts/cli.py", line 159, in search
    handler.invoke(data)
  File "/usr/local/lib/python2.7/site-packages/cruddy/scripts/cli.py", line 70, in invoke
    self._invoke_lambda(payload)
  File "/usr/local/lib/python2.7/site-packages/cruddy/scripts/cli.py", line 56, in _invoke_lambda
    click.echo(click.style(crud_response['error_type'], fg='red'))
  File "/usr/local/lib/python2.7/site-packages/click/termui.py", line 393, in style
    return ''.join(bits)
TypeError: sequence item 1: expected string, NoneType found
garnaat commented 8 years ago

I'm having trouble reproducing this.

pas256 commented 8 years ago

It is caused when the Lambda function does not have the dynamodb:Query permission. An access denied response is created by boto3 which the current code doesn't handle gracefully.