Repository: aws/aws-cli

Issue:
AWS CLI configuration does not respect profile variable
I tried to use the command aws ec2 describe-spot-price-history in the CLI and received the error 'You must specify a region. You can also configure your region by running "aws configure".' When I first installed the CLI, I configured my credentials and region.

Running 'aws configure', I try to re-enter my details (they are listed as blank), but they do not save. I assume this is because I am using a profile. I have the environment variable AWS_DEFAULT_PROFILE set to 'internal', and have attached my configuration files (with .txt extension added and sensitive data redacted).

[config.txt](https://github.com/aws/aws-cli/files/1486174/config.txt)
[credentials.txt](https://github.com/aws/aws-cli/files/1486175/credentials.txt)


Discussion:

Resolving patch:
diff --git a/awscli/customizations/configure/configure.py b/awscli/customizations/configure/configure.py
--- a/awscli/customizations/configure/configure.py
+++ b/awscli/customizations/configure/configure.py
@@ -112,10 +112,10 @@ def _run_main(self, parsed_args, parsed_globals):
         config_filename = os.path.expanduser(
             self._session.get_config_variable('config_file'))
         if new_values:
-            self._write_out_creds_file_values(new_values,
-                                              parsed_globals.profile)
-            if parsed_globals.profile is not None:
-                section = profile_to_section(parsed_globals.profile)
+            profile = self._session.profile
+            self._write_out_creds_file_values(new_values, profile)
+            if profile is not None:
+                section = profile_to_section(profile)
                 new_values['__section__'] = section
             self._config_writer.update_config(new_values, config_filename)
 


Test patch:
diff --git a/tests/unit/customizations/configure/__init__.py b/tests/unit/customizations/configure/__init__.py
--- a/tests/unit/customizations/configure/__init__.py
+++ b/tests/unit/customizations/configure/__init__.py
@@ -17,7 +17,7 @@ class FakeSession(object):
 
     def __init__(self, all_variables, profile_does_not_exist=False,
                  config_file_vars=None, environment_vars=None,
-                 credentials=None):
+                 credentials=None, profile=None):
         self.variables = all_variables
         self.profile_does_not_exist = profile_does_not_exist
         self.config = {}
@@ -28,7 +28,7 @@ def __init__(self, all_variables, profile_does_not_exist=False,
             environment_vars = {}
         self.environment_vars = environment_vars
         self._credentials = credentials
-        self.profile = None
+        self.profile = profile
 
     def get_credentials(self):
         return self._credentials
@@ -62,4 +62,4 @@ def emit_first_non_none_response(self, *args, **kwargs):
     def _build_profile_map(self):
         if self.full_config is None:
             return None
-        return self.full_config['profiles']
\ No newline at end of file
+        return self.full_config['profiles']
diff --git a/tests/unit/customizations/configure/test_configure.py b/tests/unit/customizations/configure/test_configure.py
--- a/tests/unit/customizations/configure/test_configure.py
+++ b/tests/unit/customizations/configure/test_configure.py
@@ -95,9 +95,9 @@ def test_some_values_changed(self):
             {'output': 'NEW OUTPUT FORMAT'}, 'myconfigfile')
 
     def test_section_name_can_be_changed_for_profiles(self):
-        # If the user specifies "--profile myname" we need to write
-        # this out to the [profile myname] section.
-        self.global_args.profile = 'myname'
+        # If the user specifies a profile we need to write this out to
+        # the [profile myname] section.
+        self.session.profile = 'myname'
         self.configure(args=[], parsed_globals=self.global_args)
         # Note the __section__ key name.
         self.assert_credentials_file_updated_with(
@@ -115,11 +115,11 @@ def test_session_says_profile_does_not_exist(self):
         # We should handle this case, and write out a new profile section
         # in the config file.
         session = FakeSession({'config_file': 'myconfigfile'},
-                              profile_does_not_exist=True)
+                              profile_does_not_exist=True,
+                              profile='profile-does-not-exist')
         self.configure = configure.ConfigureCommand(session,
                                                     prompter=self.precanned,
                                                     config_writer=self.writer)
-        self.global_args.profile = 'profile-does-not-exist'
         self.configure(args=[], parsed_globals=self.global_args)
         self.assert_credentials_file_updated_with(
             {'aws_access_key_id': 'new_value',