# Buggy code
def iter_log_events(self, log_group_name, interleaved=True):
    # type: (str, bool) -> Iterator[Dict[str, Any]]
    logs = self._client("logs")
    paginator = logs.get_paginator("filter_log_events")
    for page in paginator.paginate(logGroupName=log_group_name, interleaved=True):
        events = page["events"]
        for event in events:
            # timestamp is modeled as a 'long', so we'll
            # convert to a datetime to make it easier to use
            # in python.
            event["ingestionTime"] = self._convert_to_datetime(event["ingestionTime"])
            event["timestamp"] = self._convert_to_datetime(event["timestamp"])
            yield event


# Traceback (botocore.errorfactory.ResourceNotFoundException)
$ cat app.py
from chalice import Chalice

app = Chalice(app_name='testlambda')


@app.lambda_function()
def index(event, context):
print("foo bar baz")
return {'hello': 'world'}

$ chalice deploy
...
$ chalice logs -n index
Traceback (most recent call last):
File "chalice/chalice/cli/__init__.py", line 485, in main
return cli(obj={})
File ".virtualenvs/chalice-37/lib/python3.7/site-packages/click/core.py", line 722, in __call__
return self.main(*args, **kwargs)
File ".virtualenvs/chalice-37/lib/python3.7/site-packages/click/core.py", line 697, in main
rv = self.invoke(ctx)
File ".virtualenvs/chalice-37/lib/python3.7/site-packages/click/core.py", line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File ".virtualenvs/chalice-37/lib/python3.7/site-packages/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File ".virtualenvs/chalice-37/lib/python3.7/site-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File ".virtualenvs/chalice-37/lib/python3.7/site-packages/click/decorators.py", line 17, in new_func
return f(get_current_context(), *args, **kwargs)
File "chalice/chalice/cli/__init__.py", line 292, in logs
sys.stdout)
File "chalice/chalice/logs.py", line 19, in display_logs
for event in events:
File "S  File "S  File "S  File "S  File "S  File "rc  File "/Users/jamessarient.py", line 677, in iter_log_events
for log_message in self._iter_log_messages(pages):
File "chalice/chalice/awsclient.py", line 681, in _iter_log_messages
for page in pages:
File ".virtualenvs/chalice-37/lib/python3.7/site-packages/botocore/paginate.py", line 255, in __iter__
response = self._make_request(current_kwargs)
File ".virtualenvs/chalice-37/lib/python3.7/site-packages/botocore/paginate.py", line 332, in _make_request
return self._method(**current_kwargs)
File ".virtualenvs/chalice-37/lib/python3.7/site-packages/botocore/client.py", line 357, in _api_call
return self._make_api_call(operation_name, kwargs)
File ".virtualenvs/chalice-37/lib/python3.7/site-packages/botocore/client.py", line 661, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.errorfactory.ResourceNotFoundException: An error occurred (ResourceNotFoundException) when calling the FilterLogEvents operation: The specified log group does not exist.

# Fixed code
def iter_log_events(self, log_group_name, interleaved=True):
    # type: (str, bool) -> Iterator[Dict[str, Any]]
    logs = self._client("logs")
    paginator = logs.get_paginator("filter_log_events")
    pages = paginator.paginate(logGroupName=log_group_name, interleaved=True)
    try:
        for log_message in self._iter_log_messages(pages):
            yield log_message
    except logs.exceptions.ResourceNotFoundException:
        # If the lambda function exists but has not been invoked yet,
        # it's possible that the log group does not exist and we'll get
        # a ResourceNotFoundException.  If this happens we return instead
        # of propagating an exception back to the user.
        pass