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

KeyError: 'key' #135

Closed
fidiego opened this issue Oct 12, 2016 · 3 comments
Closed

KeyError: 'key' #135

fidiego opened this issue Oct 12, 2016 · 3 comments
Labels

Comments

@fidiego
Copy link

fidiego commented Oct 12, 2016

I deployed several times with success, but at some point I started seeing the following error on chalice deploy --profile <profile>

Updating IAM policy.
Error: Error when deploying: 'key'

I narrowed down the issue to chalice gen-key

% chalice gen-policy --filename app.py                                                                                              ~/code/immigrant-defense-project/map-demo/backend
Traceback (most recent call last):
  File "/Users/fidiego/.virtualenvs/map-demo-backend/bin/chalice", line 11, in <module>
    sys.exit(main())
  File "/Users/fidiego/.virtualenvs/map-demo-backend/lib/python2.7/site-packages/chalice/cli/__init__.py", line 236, in main
    return cli(obj={})
  File "/Users/fidiego/.virtualenvs/map-demo-backend/lib/python2.7/site-packages/click/core.py", line 716, in __call__
    return self.main(*args, **kwargs)
  File "/Users/fidiego/.virtualenvs/map-demo-backend/lib/python2.7/site-packages/click/core.py", line 696, in main
    rv = self.invoke(ctx)
  File "/Users/fidiego/.virtualenvs/map-demo-backend/lib/python2.7/site-packages/click/core.py", line 1060, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/fidiego/.virtualenvs/map-demo-backend/lib/python2.7/site-packages/click/core.py", line 889, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/fidiego/.virtualenvs/map-demo-backend/lib/python2.7/site-packages/click/core.py", line 534, in invoke
    return callback(*args, **kwargs)
  File "/Users/fidiego/.virtualenvs/map-demo-backend/lib/python2.7/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/Users/fidiego/.virtualenvs/map-demo-backend/lib/python2.7/site-packages/chalice/cli/__init__.py", line 200, in gen_policy
    generated = policy.policy_from_source_code(contents)
  File "/Users/fidiego/.virtualenvs/map-demo-backend/lib/python2.7/site-packages/chalice/policy.py", line 20, in policy_from_source_code
    client_calls = get_client_calls_for_app(source_code)
  File "/Users/fidiego/.virtualenvs/map-demo-backend/lib/python2.7/site-packages/chalice/analyzer.py", line 67, in get_client_calls_for_app
    t.bind_types(parsed)
  File "/Users/fidiego/.virtualenvs/map-demo-backend/lib/python2.7/site-packages/chalice/analyzer.py", line 283, in bind_types
    self.visit(parsed_code.parsed_ast)
  File "/Users/fidiego/.virtualenvs/map-demo-backend/lib/python2.7/site-packages/chalice/analyzer.py", line 437, in visit
    return ast.NodeVisitor.visit(self, node)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ast.py", line 241, in visit
    return visitor(node)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ast.py", line 249, in generic_visit
    self.visit(item)
  File "/Users/fidiego/.virtualenvs/map-demo-backend/lib/python2.7/site-packages/chalice/analyzer.py", line 437, in visit
    return ast.NodeVisitor.visit(self, node)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ast.py", line 241, in visit
    return visitor(node)
  File "/Users/fidiego/.virtualenvs/map-demo-backend/lib/python2.7/site-packages/chalice/analyzer.py", line 314, in visit_Assign
    self.generic_visit(node)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ast.py", line 251, in generic_visit
    self.visit(value)
  File "/Users/fidiego/.virtualenvs/map-demo-backend/lib/python2.7/site-packages/chalice/analyzer.py", line 437, in visit
    return ast.NodeVisitor.visit(self, node)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ast.py", line 241, in visit
    return visitor(node)
  File "/Users/fidiego/.virtualenvs/map-demo-backend/lib/python2.7/site-packages/chalice/analyzer.py", line 369, in visit_Call
    self._infer_function_call(node)
  File "/Users/fidiego/.virtualenvs/map-demo-backend/lib/python2.7/site-packages/chalice/analyzer.py", line 395, in _infer_function_call
    child_infer.bind_types(ParsedCode(ast_node, sub_table))
  File "/Users/fidiego/.virtualenvs/map-demo-backend/lib/python2.7/site-packages/chalice/analyzer.py", line 283, in bind_types
    self.visit(parsed_code.parsed_ast)
  File "/Users/fidiego/.virtualenvs/map-demo-backend/lib/python2.7/site-packages/chalice/analyzer.py", line 437, in visit
    return ast.NodeVisitor.visit(self, node)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ast.py", line 241, in visit
    return visitor(node)
  File "/Users/fidiego/.virtualenvs/map-demo-backend/lib/python2.7/site-packages/chalice/analyzer.py", line 417, in visit_FunctionDef
    self.visit(child)
  File "/Users/fidiego/.virtualenvs/map-demo-backend/lib/python2.7/site-packages/chalice/analyzer.py", line 437, in visit
    return ast.NodeVisitor.visit(self, node)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ast.py", line 241, in visit
    return visitor(node)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ast.py", line 249, in generic_visit
    self.visit(item)
  File "/Users/fidiego/.virtualenvs/map-demo-backend/lib/python2.7/site-packages/chalice/analyzer.py", line 437, in visit
    return ast.NodeVisitor.visit(self, node)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ast.py", line 241, in visit
    return visitor(node)
  File "/Users/fidiego/.virtualenvs/map-demo-backend/lib/python2.7/site-packages/chalice/analyzer.py", line 314, in visit_Assign
    self.generic_visit(node)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ast.py", line 251, in generic_visit
    self.visit(value)
  File "/Users/fidiego/.virtualenvs/map-demo-backend/lib/python2.7/site-packages/chalice/analyzer.py", line 437, in visit
    return ast.NodeVisitor.visit(self, node)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ast.py", line 241, in visit
    return visitor(node)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ast.py", line 251, in generic_visit
    self.visit(value)
  File "/Users/fidiego/.virtualenvs/map-demo-backend/lib/python2.7/site-packages/chalice/analyzer.py", line 437, in visit
    return ast.NodeVisitor.visit(self, node)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ast.py", line 241, in visit
    return visitor(node)
  File "/Users/fidiego/.virtualenvs/map-demo-backend/lib/python2.7/site-packages/chalice/analyzer.py", line 341, in visit_Call
    self.generic_visit(node)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ast.py", line 251, in generic_visit
    self.visit(value)
  File "/Users/fidiego/.virtualenvs/map-demo-backend/lib/python2.7/site-packages/chalice/analyzer.py", line 437, in visit
    return ast.NodeVisitor.visit(self, node)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ast.py", line 241, in visit
    return visitor(node)
  File "/Users/fidiego/.virtualenvs/map-demo-backend/lib/python2.7/site-packages/chalice/analyzer.py", line 327, in visit_Attribute
    self.generic_visit(node)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ast.py", line 251, in generic_visit
    self.visit(value)
  File "/Users/fidiego/.virtualenvs/map-demo-backend/lib/python2.7/site-packages/chalice/analyzer.py", line 437, in visit
    return ast.NodeVisitor.visit(self, node)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ast.py", line 241, in visit
    return visitor(node)
  File "/Users/fidiego/.virtualenvs/map-demo-backend/lib/python2.7/site-packages/chalice/analyzer.py", line 307, in visit_Name
    node.inferred_type = self._symbol_table.get_inferred_type(node.id)
  File "/Users/fidiego/.virtualenvs/map-demo-backend/lib/python2.7/site-packages/chalice/analyzer.py", line 214, in get_inferred_type
    symbol = self._local_table.lookup(name)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/symtable.py", line 100, in lookup
    flags = self._table.symbols[name]
KeyError: 'key'
@jamesls
Copy link
Member

jamesls commented Oct 12, 2016

Thanks. Could you share a snippet of your (sanitized) view function? It would help to have the code snippet that's causing the policy generator to crash so I can add a test for this.

@jamesls jamesls added the bug label Oct 12, 2016
@fidiego
Copy link
Author

fidiego commented Oct 12, 2016

@jamesls

tree

.
├── app.py
├── config.yml
└── requirements.txt

0 directories, 3 files

app.py

import time
import logging
import os
import yaml

from chalice import Chalice


BASE_DIR = os.path.dirname(os.path.abspath('__file__'))
CONFIG_LOCATION = os.path.join(BASE_DIR, 'config.yml')


def load_conf():
    with open(CONFIG_LOCATION, 'r') as conf_file:
        configs = yaml.load(conf_file.read())
        settings = {key.upper(): value for key, value in configs.iteritems()}
    logging.info('loaded configs from {}'.format(CONFIG_LOCATION))
    return settings


SETTINGS = load_conf()


app = Chalice(app_name='backend')


@app.route('/')
def index():
    return {'hello': 'world'}


@app.route('/ping')
def ping():
    return {'success': True, 'time': int(time.time())}

@jamesls
Copy link
Member

jamesls commented Oct 13, 2016

Perfect, thanks. Looks like this is because of the use of a dict comprehension. There's an existing issue opened for this and I'm working on a fix for this. Let's track the remaining work over in #131.

@jamesls jamesls closed this as completed Oct 13, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants