Sceptre / sceptre

Build better AWS infrastructure
https://docs.sceptre-project.org
Other
1.49k stars 313 forks source link

Sceptre returns stacktrace if credentials are missing #621

Closed m1keil closed 5 years ago

m1keil commented 5 years ago

With very simple stack that doesn't contain the profile or any AWS keys under ~/.aws/config or envars:

$ sceptre --debug create stack1.yaml --yes
[2019-02-04 14:58:23] - Adding yaml constructors for the entry point groups ['sceptre.hooks', 'sceptre.resolvers']
[2019-02-04 14:58:23] - Added constructor for <class 'sceptre.hooks.asg_scaling_processes.ASGScalingProcesses'> with node tag !asg_scheduled_actions
[2019-02-04 14:58:23] - Added constructor for <class 'sceptre.hooks.cmd.Cmd'> with node tag !cmd
[2019-02-04 14:58:23] - Added constructor for <class 'sceptre.resolvers.environment_variable.EnvironmentVariable'> with node tag !environment_variable
[2019-02-04 14:58:23] - Added constructor for <class 'sceptre.resolvers.file_contents.FileContents'> with node tag !file_contents
[2019-02-04 14:58:23] - Added constructor for <class 'sceptre.resolvers.stack_output.StackOutput'> with node tag !stack_output
[2019-02-04 14:58:23] - Added constructor for <class 'sceptre.resolvers.stack_output.StackOutputExternal'> with node tag !stack_output_external
[2019-02-04 14:58:23] - Reading in 'config.yaml' files...
/Users/msverdlik/.virtualenvs/sceptre/lib/python3.7/site-packages/yaml/constructor.py:126: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
  if not isinstance(key, collections.Hashable):
[2019-02-04 14:58:23] - Config: {'project_path': '/private/tmp/testing', 'stack_group_path': '', 'project_code': 'testing', 'region': 'ap-southeast-2'}
[2019-02-04 14:58:23] - Reading in 'stack2.yaml' files...
[2019-02-04 14:58:23] - Config: {'project_path': '/private/tmp/testing', 'stack_group_path': '', 'project_code': 'testing', 'region': 'ap-southeast-2', 'template_path': 'template.yaml', 'sceptre_user_data': {'test': <sceptre.resolvers.stack_output.StackOutput object at 0x109687438>}}
[2019-02-04 14:58:23] - Reading in 'stack1.yaml' files...
[2019-02-04 14:58:23] - Config: {'project_path': '/private/tmp/testing', 'stack_group_path': '', 'project_code': 'testing', 'region': 'ap-southeast-2', 'template_path': 'template.yaml'}
[2019-02-04 14:58:23] - Generate edges for graph
[2019-02-04 14:58:23] - Generate edges for graph
[2019-02-04 14:58:23] - Added edge: None
[2019-02-04 14:58:23] - stack1 - Creating Stack
[2019-02-04 14:58:23] - No cloudformation client found, creating one...
[2019-02-04 14:58:23] - Getting Boto3 session
[2019-02-04 14:58:23] - No Boto3 session found, creating one...
[2019-02-04 14:58:23] - Using cli credentials...
Traceback (most recent call last):
  File "/Users/msverdlik/.virtualenvs/sceptre/bin/sceptre", line 11, in <module>
    load_entry_point('sceptre', 'console_scripts', 'sceptre')()
  File "/Users/msverdlik/.virtualenvs/sceptre/lib/python3.7/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/Users/msverdlik/.virtualenvs/sceptre/lib/python3.7/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/Users/msverdlik/.virtualenvs/sceptre/lib/python3.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/msverdlik/.virtualenvs/sceptre/lib/python3.7/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/msverdlik/.virtualenvs/sceptre/lib/python3.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/Users/msverdlik/.virtualenvs/sceptre/lib/python3.7/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/Users/msverdlik/src/sceptre/sceptre/cli/helpers.py", line 37, in decorated
    return func(*args, **kwargs)
  File "/Users/msverdlik/src/sceptre/sceptre/cli/create.py", line 47, in create_command
    responses = plan.create()
  File "/Users/msverdlik/src/sceptre/sceptre/plan/plan.py", line 86, in create
    return self._execute(*args)
  File "/Users/msverdlik/src/sceptre/sceptre/plan/plan.py", line 37, in _execute
    return executor.execute(*args)
  File "/Users/msverdlik/src/sceptre/sceptre/plan/executor.py", line 55, in execute
    stack, status = future.result()
  File "/usr/local/Cellar/python/3.7.2_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/concurrent/futures/_base.py", line 425, in result
    return self.__get_result()
  File "/usr/local/Cellar/python/3.7.2_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/concurrent/futures/_base.py", line 384, in __get_result
    raise self._exception
  File "/usr/local/Cellar/python/3.7.2_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/Users/msverdlik/src/sceptre/sceptre/plan/executor.py", line 62, in _execute
    result = getattr(actions, self.command)(*args)
  File "/Users/msverdlik/src/sceptre/sceptre/hooks/__init__.py", line 104, in decorated
    response = func(self, *args, **kwargs)
  File "/Users/msverdlik/src/sceptre/sceptre/plan/actions.py", line 81, in create
    kwargs=create_stack_kwargs
  File "/Users/msverdlik/src/sceptre/sceptre/connection_manager.py", line 45, in decorated
    return func(*args, **kwargs)
  File "/Users/msverdlik/src/sceptre/sceptre/connection_manager.py", line 203, in call
    client = self._get_client(service, region, profile, stack_name)
  File "/Users/msverdlik/src/sceptre/sceptre/connection_manager.py", line 171, in _get_client
    profile, region
  File "/Users/msverdlik/src/sceptre/sceptre/connection_manager.py", line 136, in _get_session
    session.get_credentials().method,
AttributeError: 'NoneType' object has no attribute 'method'

The issue is the log line in line number 134 in connection_manager.py which assumes session.get_credentials() is never None:

                self.logger.debug(
                    "Using credential set from %s: %s",
                    session.get_credentials().method,
                    {
                        "AccessKeyId": mask_key(
                            session.get_credentials().access_key
                        ),
                        "SecretAccessKey": mask_key(
                            session.get_credentials().secret_key
                        ),
                        "Region": session.region_name
                    }
                )

Adding a quick if session.get_credentials() is not None seem to solve this one. Let me know if I should PR that.

ngfgrant commented 5 years ago

👍 yes please @m1keil :)